Nested loops
Python · Unit 3: Loops
- Full plan
- Python
- 9 exercises
You can put a loop inside another one.
For each round of the outer one, the inner one runs all of its rounds.
for i in range(2):
for j in range(3):
print(i, j)Prints
0 0 0 1 0 2 1 0 1 1 1 2
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 stars does this code print?
3. Predict the output
A room has 2 tables with 2 chairs each. What does it print?
4. Predict the output
What does this code print?
5. Complete the code
Complete this so it prints
6. Predict the output
What does this code print?
7. Find the bug
This program should draw a rectangle of 3 rows with 4 stars each. Which line has the error?
8. Put the lines in order
Put the lines in order to print the 1 times table and the 2 times table, from 1 to 3, each on its own row.
9. Predict the output
What does this code print?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.