Chapter 5.13 problem 3

im trying to figure out how to bump incrementally up my squares, can anybody help understanding how to do that and deliver it back to a function/loop. i assume its something like sz += 20 but i cant find out how to do it correctly?

thanks

import turtle

def draw_square(t, sz):
for i in range(4):
t.forward(sz)
t.left(90)

def main():
wn = turtle.Screen()
wn.bgcolor(“lightgreen”)

alex = turtle.Turtle()    
alex.color('hotpink')
alex.pensize(3)

for i in range(5):
    draw_square(alex, 20)

    #draw_square(alex, sz = 20 + sz)
    draw_square(sz = 20 + sz)

    alex.penup()
    alex.forward(40)
    alex.left(90)
    alex.pendown()

wn.exitonclick()

if name == “main”:
main()

A simple sz = sz + 20, or some such, should be proper syntax. Though I am not sure if you can calculate that value within a function call-- you might want to do it outside the call.

1 Like

Hello,

Looking at your code…

  • First I noted that you have not assigned a initial value to the variable sz… so you could have some trouble running your code.
  • Also, I think the increments can be associated with the variable ‘i’ in the for. Like when ‘i’ == 0 draw the square with the first size, then ‘i’ == 1 draw the second square with the bigger size . . .

Hope I could help