# 3.5. Practice Makes Perfect¶

Turtle Commands

Command

What does it do?

`forward( distance )`

Move forward a specified distance

`backward( distance )`

Move backward a specified distance

`left(90)`

Turns 90 degrees to the left (you can use any angle, not just 90!)

`right(90)`

Turns 90 degrees to the right

`circle( radius )`

Draws a circle with the specified radius

`goto( x, y )`

Move straight to the position with coordinates (x, y). Note: the center is (0, 0)

`up()`

Stop leaving a trail

`down()`

Start drawing a trail

`color( c )`

Set the color to c (https://trinket.io/docs/colors)

`for i in range( n ):`

Repeat n times

If you don’t remember what these commands do, give them a try below!

System Message: ERROR/3 (/home/bmiller/Runestone/web2py/applications/runestone/books/technovation/_sources/2-Loops/exercises.rst, line 31)

Duplicate ID – see 2-Basics/exercises, line 84

```.. activecode:: command-review-wk2
:language: python
:nocodelens:

import turtle

turtle.forward(100)
turtle.backward(100)

# try out some other commands here!

```

Let’s take another look at drawing a square. How could we re-write it using a loop?

System Message: ERROR/3 (/home/bmiller/Runestone/web2py/applications/runestone/books/technovation/_sources/2-Loops/exercises.rst, line 48)

Duplicate ID – see 2-Basics/exercises, line 152

```.. activecode:: square-loop
:language: python
:nocodelens:

import turtle

turtle.forward(100)
turtle.left(90)

turtle.forward(100)
turtle.left(90)

turtle.forward(100)
turtle.left(90)

turtle.forward(100)
turtle.left(90)
```

Let’s use what we know about loops to draw a dashed line across the entire box!
The code below draws two dashes. See if you can modify it to use a loop!

System Message: ERROR/3 (/home/bmiller/Runestone/web2py/applications/runestone/books/technovation/_sources/2-Loops/exercises.rst, line 77)

Duplicate ID – see 2-Basics/exercises, line 181

```.. activecode:: dashed-line
:language: python
:nocodelens:

import turtle

# draw the first dash
turtle.forward(10)

# pick the pen up to leave white space between dashes
turtle.penup()
turtle.forward(10)

# put the pen down and draw the second dash
turtle.pendown()
turtle.forward(10)

turtle.penup()
turtle.forward(10)
```

Why stop with squares? Shapes with any number of sides can be drawn using a loop!
Start with your code that draws a square. Then, change the number of times the loop repeats and the angle that you turn each time to see if you can draw these shapes.

System Message: ERROR/3 (/home/bmiller/Runestone/web2py/applications/runestone/books/technovation/_sources/2-Loops/exercises.rst, line 114)

Duplicate ID – see 2-Basics/exercises, line 218

```.. activecode:: shapes-loop
:language: python
:nocodelens:

import turtle
```

Try converting you dashed line into a row of circles! Let’s draw 20 circles, each with a radius of 10.

System Message: ERROR/3 (/home/bmiller/Runestone/web2py/applications/runestone/books/technovation/_sources/2-Loops/exercises.rst, line 130)

Duplicate ID – see 2-Basics/exercises, line 234

```.. activecode:: circle-row
:language: python
:nocodelens:

import turtle
```

Try drawing a row of squares!

System Message: ERROR/3 (/home/bmiller/Runestone/web2py/applications/runestone/books/technovation/_sources/2-Loops/exercises.rst, line 154)

Duplicate ID – see 2-Basics/exercises, line 258

```.. activecode:: square-row
:language: python
:nocodelens:

import turtle
```

Try drawing a plus sign using a loop!
If you’re not sure how to do it with a loop, try writing it out line by line first. Once you’ve got it drawing a plus sign, see if you can put any repeated code in a loop!

System Message: ERROR/3 (/home/bmiller/Runestone/web2py/applications/runestone/books/technovation/_sources/2-Loops/exercises.rst, line 172)

Duplicate ID – see 2-Basics/exercises, line 276

```.. activecode:: plus
:language: python
:nocodelens:

import turtle
```

```.. activecode:: asterisk