Lesson 3: Any shape
Halaman ini memerlukan browser terbaru (dengan dukungan SharedArrayBuffer). Silakan perbarui Chrome, Edge, Firefox, atau Safari ke versi terbaru.
English
The 360 rule
- To draw a shape with
nequal sides, turn360 / ndegrees at each corner. - Square: 360 / 4 = 90. Triangle: 360 / 3 = 120.
Words for this lesson
| Word | Meaning |
|---|---|
| polygon | a closed shape with straight sides |
| hexagon | a polygon with 6 sides |
| variable | a name for a value, like sides = 6 |
English
Change one number
import turtle
sides = 5
for i in range(sides):
turtle.forward(80)
turtle.left(360 / sides)
- Change
sidesto 6, 8 or 10. The loop does the rest.
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
Draw a hexagon: 6 equal sides of 80 steps. Use a loop and the 360 rule.
Klik Jalankan untuk melihat output di sini.
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
Draw an octagon (8 sides) with sides of 50 steps. A stop sign has this shape.
Klik Jalankan untuk melihat output di sini.