'{Beginner Turtle graphics} Nested while loop runs infinitely?
I can execute the code fine and everything but I want it to stop running after the 8 tails are complete. I've been having similar issues with other nested loop projects where even with the condition defined, the loop refuses to stop running. Any help will be greatly appreciated!
The code:
import turtle
turtle.width(20)
turtle.speed(0)
#outerloop: pink tail
turtle.up()
tail_count = 0
while tail_count < 8:
turtle.color("salmon")
turtle.goto(0,0)
turtle.down()
turtle.circle(75,180)
#innerloop: yellow ends
end_count = 0
while end_count < 4:
turtle.color("yellow")
turtle.circle(30,45)
turtle.color("gold")
turtle.circle(30,45)
turtle.color("yellow")
turtle.circle(30,45)
turtle.color("gold")
turtle.circle(30,45)
turtle.up()
end_count = end_count + 1
turtle.left(45)
tail_count = tail_count + 1
turtle.done()
Solution 1:[1]
This line: tail_count = tail_count + 1
Is not inside the first while loop so tail_count is not getting bigger inside the loop.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kleinohad |
