while
Python · Unit 3: Loops
- Full plan
- Python
- 9 exercises
while repeats the block as long as its condition is True.
It checks the condition before each round. When it gives False, it moves on to what comes next.
n = 1
while n <= 3:
print(n)
n += 1
print("Done")Prints
1 2 3 Done
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Multiple choice
How many times does this code print something?
3. Predict the output
What does this code print?
4. Multiple choice
What would happen if you deleted the line
lives -= 1?5. Complete the code
Maya saves 30 a week. Complete this to count how many weeks it takes her to save at least 100.
6. Find the bug
This program should print the powers of 2 up to 64 (1, 2, 4… 64). Which line has the error?
7. Predict the output
The person types 5, then 3 and then 0. What does it print?
8. Put the lines in order
Put the lines in order to show the battery while there is charge left. Each hour uses 30.
9. Multiple choice
If the person types 2026, what does this code do?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.