Lesson 2: Loops draw shapes
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
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.
Độ khó 1/5 · 100 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Draw a square with sides of 120 steps. Use a for loop.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Draw a triangle with 3 equal sides of 150 steps. Use a loop. Hint: the turtle turns 120 degrees at each corner.
Nhấn Chạy để xem kết quả ở đây.