Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Turtle Collision
    text
    copied!<p>How do I make the collision? so the turtle/snake doesn't go out of the box. Trying to make them stay inside the (-200, -200) and (200, 200).</p> <pre><code>from turtle import * from random import * def bounding_box(): up() right(90) forward(200) down() left(90) forward(200) left(90) forward(400) left(90) forward(400) left(90) forward(400) left(90) forward(200) up() goto(0,0) down() def drawSnakeRec(segments, length): if segments &lt;= 0 or length &lt;= 0: return 0 else: color(random(), random(), random()) forward(length) pensize(randint(1,10)) left(randint(-30, 30)) return length + drawSnakeRec(segments - 1, randint(1,20)) def drawSnakeIter(segments, length): TL = 0 while segments &gt; 0: color(random(), random(), random()) pensize(randint(1,10)) forward(length) left(randint(-30, 30)) TL += length segments -=1 return TL def main(): segments = int(input("Enter the segments between 0 and 500: ")) bounding_box() hideturtle() speed('fast') if segments &lt; 0 or segments &gt; 500: print("Segments is out of range. Segment must be between 0 and 500 inclusive") input("Press enter to close") else: x = drawSnakeRec(segments, randint(1, 20)) print("Recursive Snake's Length is:",x,"Units") input("Press Enter to go on Iterative Snake") up() goto(0,0) reset() bounding_box() y = drawSnakeIter(segments, randint(1,20)) print("Iterative Snake's Length is:",y," Units") input("Press Enter to exit...") bye() main() </code></pre> <p>Any help? Thank you. So, I am trying to finish this up. Yes this is the lab homework I am trying to finish. It would be great if you guys can help me or provide me something that I can do. PS: I am bad at turtle. I have never learned turtle before, well I have learn python a little bit.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload