0

I have this code:
def rollBox(length, numDivisions, count):
Angle = 90/numDivisions
if count == 0:
return
elif numDivisions == 0:
rollBox(length, numDivisions, count - 1)
else:
square(length)
turtle.right(Angle)
rollBox(length, numDivisions - 1, count)

Is there any way to still decrease the 'numDivisions' parameter to zero while still keeping its original value? I don't know if that makes sense, but I don't want the original value to change because I want the turtle to rotate at the same angle each time. I'm getting a divide by zero error.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by pyTony
0

you could just create a copy of numDivisions at the start of the function then use the copy of numDivisions whenever you want the original value.

Edited by winmic: n/a

0

I do not quite get what is your purpose. Something like this?

import turtle

def square(length):
    for i in range(4):
        turtle.forward(length)
        turtle.right(90)

def roll_box(length, num_divisions):
    turtle.fill(True)
    turtle.down()
    for count in range(num_divisions):
        angle = 360.0/num_divisions
        square(length)
        turtle.right(angle)

turtle.reset()
turtle.setup(width=1000, height=600, startx=0, starty=0)
roll_box(100,12)
turtle.mainloop()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.