Advertisement
TonyMo

turtlerace.py

Feb 20th, 2021
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # 1 5 turtle race
  2. # ref: 1 5 Turtle race - Object-oriented Programming in Python
  3. #  - Raspberry Pi Foundation.htm
  4.  
  5. # ask Python to import the Turtle class,
  6. from turtle import Turtle
  7.  
  8. # Create an instance of a Turtle object.
  9.  
  10. axel = Turtle()
  11. axel.color('red')   # define attribute which is defined in Turtle
  12. axel.shape('turtle')   # define attribute which is defined in Turtle
  13. axel.penup()    # call methods
  14. axel.goto(-160, 100)
  15. axel.pendown()
  16.  
  17. bullet = Turtle()
  18. bullet.color('green')   # define attribute which is defined in Turtle
  19. bullet.shape('turtle')   # define attribute which is defined in Turtle
  20. bullet.penup()    # call methods
  21. bullet.goto(-160, 70)
  22. bullet.pendown()
  23.  
  24. flash = Turtle()
  25. flash.color('blue')   # define attribute which is defined in Turtle
  26. flash.shape('turtle')   # define attribute which is defined in Turtle
  27. flash.penup()    # call methods
  28. flash.goto(-160, 40)
  29. flash.pendown()
  30.  
  31. zippy = Turtle()
  32. zippy.color('brown')   # define attribute which is defined in Turtle
  33. zippy.shape('turtle')   # define attribute which is defined in Turtle
  34. zippy.penup()    # call methods
  35. zippy.goto(-160, 10)
  36. zippy.pendown()
  37.  
  38. from random import randint
  39.  
  40. for movement in range(100):
  41.     axel.forward(randint(1,5))
  42.     bullet.forward(randint(1,5))
  43.     flash.forward(randint(1,5))
  44.     zippy.forward(randint(1,5))
  45.  
  46. # How to close the turtle window?
  47. # input("Press Enter to close")
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement