World 2: Loops
Long roads
- The roads are longer now. Ten
rightlines? Too many! - A loop repeats lines for you.
Words for this world
| Word | Meaning |
|---|---|
| loop | code that runs again and again |
| repeat | do the same thing one more time |
| pattern | moves that come again in the same order |
Repeat a move
- Everything inside the loop repeats.
- Find the pattern on the map, then put it inside the loop.
for i in range(3):
print("right")
print("down")
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Home is 10 squares to the right. Do not write 10 lines: use a loop.
Click Run to see the output here.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Walk down the stairs: right, down, right, down… Repeat the two moves with a loop.
Click Run to see the output here.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Every second square has a star. Use a loop that moves right two times on each turn.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Find the pattern: right, right, down. Repeat it with a loop.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Go right to the end, down two squares, then left all the way home. Use a loop for each long walk.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Walk around the garden and collect all 4 stars. Home is just below the start, so you finish there.
Click Run to see the output here.