Lesson 2: Loops draw shapes
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Let a loop repeat
- The square had the same two lines four times.
- A
forloop repeats them for you.
Words for this lesson
| Word | Meaning |
|---|---|
| loop | code that runs again and again |
| repeat | do the same thing one more time |
| indent | the spaces at the start of a line inside the loop |
English
A square in three lines
import turtle
for i in range(4):
turtle.forward(100)
turtle.left(90)
- Both indented lines repeat 4 times.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Draw a square with sides of 120 steps. Use a for loop.
点击“运行”查看此处输出。
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Draw a triangle with 3 equal sides of 150 steps. Use a loop. Hint: the turtle turns 120 degrees at each corner.
点击“运行”查看此处输出。