Chapter 7a - While Loop
A while loop repeats as long as the test is true.
n = 3
while n > 0:
print(n)
n = n - 1
π§ͺ Try it
Mini quiz β while testβ
while test
1 / 2How many numbers are printed before done?
n = 3while n > 0:print(n)n = n - 1print("done")
Pick an answer to see if you are right.
Challenge: countdownβ
Write countdown(n) so it prints n, then n-1, ... then 1 (do not print 0).
Expected for 3:
3
2
1
Mini quiz β whileβ
while
1 / 1When does a while loop stop?
Pick an answer to see if you are right.
Exercisesβ
Activity: Keep going?
Write keep_going(letter) so it returns True if the letter is y, otherwise False.
(This is the question you ask at the end of a while loop.)