1/8
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a while loop?
It allows you to repeat lines of code as long as a condition is true, conditionally
How can I use a while loop to print out numbers 1 to 10:
count = 1
while count < 11:
print(count)
count = count + 1
What is a for loop?
Used to repeat a sequence of steps a certain number of times.
What part of a for loop states the number of times that the indented code will be repeated
range
Write a for loop of a user saying the number of times something will be printed.
times = int(input(“Enter the number of times: “))
for count in range (times):
print (“This is the answer”)
How can I print out the value of the count variable?
for count in range (4):
print (count)
0
1
2
3
Write code specifying the start and end point for the count
for number in range (20,24):
print (number)
20
21
22
23
Write a code specifiying the start and finish and adding a step of 2
for number in range (1,10,2):
print (number)
1
3
5
7
9