This function displays output on the screen.
print()
A programming structure used to repeat instructions.
Loop
The keyword used to start this loop.
for
The keyword used to create this loop.
while
This statement immediately exits a loop.
break
This function allows the user to enter data.
input()
Python has two main loops taught in this course.
for and while
This function generates a sequence of numbers for loops.
range()
This controls whether the loop continues running.
Condition
This statement skips the current iteration and continues to the next.
continue
This symbol assigns a value to a variable.
=
This loop repeats code while a condition is true.
while loop
How many times will this run?
for i in range(5)
5
What happens if the condition never becomes false?
Infinite loop
What will be printed?
for i in range(5):
if i==3:
break
print(i)
0 1 2
This data type stores whole numbers.
int
This loop is usually used with range() to repeat a certain number of times.
for loop
What is the last value of i?
for i in range(1,6)
5
What will be printed?
x=1
while x<=3:
print(x)
x+=1
1 2 3
What will be printed?
for i in range(5):
if i==2:
continue
print(i)
0 1 3 4
This function converts input into a whole number.
int()
A loop that never stops running.
Infinite loop
How many iterations occur?
for x in range(2,10,2)
4 iterations (2,4,6,8)
How many times will this loop run?
x=4
while x>0:
x-=1
4 times
What will be printed?
for i in range(1,6):
if i==4:
break
print(i)
1 2 3