Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1 5 turtle race
- # ref: 1 5 Turtle race - Object-oriented Programming in Python
- # - Raspberry Pi Foundation.htm
- # ask Python to import the Turtle class,
- from turtle import Turtle
- # Create an instance of a Turtle object.
- axel = Turtle()
- axel.color('red') # define attribute which is defined in Turtle
- axel.shape('turtle') # define attribute which is defined in Turtle
- axel.penup() # call methods
- axel.goto(-160, 100)
- axel.pendown()
- bullet = Turtle()
- bullet.color('green') # define attribute which is defined in Turtle
- bullet.shape('turtle') # define attribute which is defined in Turtle
- bullet.penup() # call methods
- bullet.goto(-160, 70)
- bullet.pendown()
- flash = Turtle()
- flash.color('blue') # define attribute which is defined in Turtle
- flash.shape('turtle') # define attribute which is defined in Turtle
- flash.penup() # call methods
- flash.goto(-160, 40)
- flash.pendown()
- zippy = Turtle()
- zippy.color('brown') # define attribute which is defined in Turtle
- zippy.shape('turtle') # define attribute which is defined in Turtle
- zippy.penup() # call methods
- zippy.goto(-160, 10)
- zippy.pendown()
- from random import randint
- for movement in range(100):
- axel.forward(randint(1,5))
- bullet.forward(randint(1,5))
- flash.forward(randint(1,5))
- zippy.forward(randint(1,5))
- # How to close the turtle window?
- # input("Press Enter to close")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement