siegel - 1 year ago 111

Python Question

Trying to make concentric squares in python with Turtle. Here's my attempt:

`import turtle`

def draw_square(t, size):

for i in range(4):

t.forward(size)

t.left(90)

wn = turtle.Screen()

dan = turtle.Turtle()

sizevar = 1

for i in range(10):

draw_square(dan,sizevar)

sizevar += 20

dan.penup()

dan.backward(sizevar/ 2)

dan.right(90)

dan.forward(sizevar / 2)

dan.left(90)

dan.pendown()

I'm not sure why they aren't concentric, my

`dan.backward(sizevar/2)`

`dan.forward(sizevar/2)`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

It should be like this:

```
import turtle
def draw_square(t, size):
for i in range(4):
t.forward(size)
t.left(90)
wn = turtle.Screen()
dan = turtle.Turtle()
sizevar = 1
for i in range(10):
draw_square(dan, sizevar)
sizevar += 20
dan.penup()
dan.backward(10)
dan.right(90)
dan.forward(10)
dan.left(90)
dan.pendown()
```

Each square is only 10 pixels outside the previous.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**