import random while(1): r = random.randint(1,10) go (r) r = random.randint(-90, 90) turn (r)
theres the code since its hard to read in the pic
import random while(1): r = random.randint(1,10) go (r) r = random.randint(-90, 90) turn (r)
theres the code since its hard to read in the pic
import random
while(1):
r = random.randint(1,10)
go (r)
r = random.randint(-90, 90)
turn (r)
When debugging a problem like this, it might be worthwhile to print out the value of each instruction as you perform it. Hopefully your turtle environment has a way to print values to some window on the screen. You might do something like this:
while(1):
r = random.randint(1,10)
print "going:", r
go (r)
r = random.randint(-90, 90)
print "turning:", r
turn (r)
This technique goes by many names, but the one I like is "When in doubt, print more out." Doing this may provide some insight into why your turtle is showing the behaviour you see.
Try printing out the values. Here's a little Python program based on your code snippet that does this:
import random
while(1):
distance = random.randint(1,10)
angle = random.randint(-90, 90)
print distance, angle
I tried this myself, and at no point does angle "get stuck". I suspect there may be some sort of bug in python turtle, but without trying out in that environment it's hard to say for sure.
Is there a way to ask python turtle for the current angle of the turtle? You may want to print that value out as well.
Hey Ryan,
I am the creator of PythonTurtle.
First of all, I'm really honored to see the first question about it in StackOverflow.
About your question: I tried running the code, and it didn't produce the bug, but since this is involving randomness, I can't really reproduce what happened in your computer.
It seems like a bug, but I can't really guess what is causing it. If this kind of bug happens to you again, preferably when randomness is not involved, I'd appreciate if you'll send me the screenshot and the code snippet. My mail is [email protected].