World 2: Loops
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
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 |
English
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")
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Home is 10 squares to the right. Do not write 10 lines: use a loop.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Walk down the stairs: right, down, right, down… Repeat the two moves with a loop.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Every second square has a star. Use a loop that moves right two times on each turn.
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Find the pattern: right, right, down. Repeat it with a loop.
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Go right to the end, down two squares, then left all the way home. Use a loop for each long walk.
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Walk around the garden and collect all 4 stars. Home is just below the start, so you finish there.
点击“运行”查看此处输出。