Lesson 2: Loops draw shapes
Esta página necesita un navegador reciente (con soporte para SharedArrayBuffer). Por favor, actualiza Chrome, Edge, Firefox o Safari a la última versión.
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.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Draw a square with sides of 120 steps. Use a for loop.
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
Draw a triangle with 3 equal sides of 150 steps. Use a loop. Hint: the turtle turns 120 degrees at each corner.
Haz clic en Ejecutar para ver la salida aquí.