In this challenge we will create a Python script to complete a Turtle race with four turtles racing across the screen.
We have started the code for you to set up the pitch of grass. You will complete this project step by step in order to:
- Add a start line to the left of the screen,
Add a finish line to the right of the screen,
Add four turtles on the start line,
Animate the turtles to race across the screen,
Find out which turtle is first to cross the finish line
Here is the Python code that you will need to complete:
Step 1: Adding a start line

To draw the start line as a vertical line on the left hand side of the screen, we will need to use the following (x,y) coordinates to tell the computer where does the start line starts and ends:

You will can add the following code to the above trinket to draw the start line:
#Let's draw the start line myPen.penup() myPen.goto(-160, 150) myPen.pendown() myPen.goto(-160, 0)
Step 2: Adding a finish line

It’s now your turn to use very similar code, this time to draw the finish line using the following (x,y) coordinates:

View Solution!
Step 3: Adding four turtles on the start line
We are now going to add the four competitors on the start line. We will have four turtles that we will need to position using the following (x,y) coordinates:

Here is the code to add the red turtle at position (-180, 140):
#Let's add our turtles
redTurtle = turtle.Turtle()
redTurtle.shape('turtle')
redTurtle.color('red')
redTurtle.pensize(2)
redTurtle.penup()
redTurtle.goto(-180, 140)
redTurtle.pendown()
Can you add some more lines of code to add 3 more turtles using the following coordinates:
- Green Turtle at position (-180,110)
- Blue Turtle at position (-180,80)
- Yellow Turtle at position (-180,50)
Step 4: Animating the turtles to race across the screen

It’s now time for our turtles to race across the screen. To do so we will use an infinite while loop. Within each iteration of the loop, we will move each turtle forward by a randomly generated number of pixels between 1 and 8.
Here is the code to use for our infinite loop…
#Let's start the race! while True: redTurtle.forward(random.randint(1,8)) greenTurtle.forward(random.randint(1,8)) blueTurtle.forward(random.randint(1,8)) yellowTurtle.forward(random.randint(1,8))
Step 5: And the winner is…
As you can see with step 4, the four turtles carry on racing even after crossing the finish line. They even disappearing off screen!
Our aim is now to check, within each iteration of the while loop, to see if one of the four turtles has reached the finish line. To do so, we will need to check the x coordinate of each turtle. A turtle with an x coordinate greater than 180 has crossed the finish line!
Here is the final code for our racing loop!
#Let's start the race!
while True:
redTurtle.forward(random.randint(1,8))
greenTurtle.forward(random.randint(1,8))
blueTurtle.forward(random.randint(1,8))
yellowTurtle.forward(random.randint(1,8))
if redTurtle.xcor()>180:
print("Red Turtle wins!")
break
elif greenTurtle.xcor()>180:
print("Green Turtle wins!")
break
elif blueTurtle.xcor()>180:
print("Blue Turtle wins!")
break
elif yellowTurtle.xcor()>180:
print("Yellow Turtle wins!")
break

Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area

















Customer A is looking for a laptop computer to work on the train when commuting to work. They need a Windows laptop that is easy to carry around so would like a screen size of less than 16 inches. They would like the laptop to be touchscreen and would need an SSD drive of at least 512GB. They can spend up to £500 on this laptop.
Customer B is looking for a multimedia desktop computer to watch movies and stream music online. They would like a dual core or a quad core CPU with a clock speed of at least 2.5Ghz. They would like a HDD drive of at least 2TB (2000GB). They would like a large screen of at least 16 inches.
Customer C is a graphic designer who would like a desktop computer to use graphic editing and photo-editing software. They are looking for a MacOS desktop computer with a touchscreen of 17 inches. They would need an SSD drive of at least 256GB and a secondary hard drive to backup their work with at least 1TB (1000GB). They are happy to spend up to £600 on their computer.
Customer D is a student who needs a laptop to take notes during lectures. They have a small budget (up to £350) and would like a computer with at 6GB or 8GB of RAM, a screen size between 14 to 16 inches, a secondary drive either HDD or SSD of at least 512GB and the Windows operating system already installed.
Customer E is looking for a laptop to be used by his family around the house. They would prefer it to be a dual core laptop with at least 8GB of RAM. They would like a touchscreen of 15.6 inches and an SSD drive of either 256GB or 512GB.
Warning: When completing the following extension tasks, note that, on this online system, Boolean values are actually stored as string containing the values “TRUE” and “FALSE”. This means that, in your queries, you will need to use “speechmarks” when storing the values “TRUE” and “FALSE” as string instead of Boolean values.
Milly Spoke is looking for a hybrid bike to commute every day to her college. She would like a bike in the price range of £150 to £250. Ideally her bike should not be too heavy so she is looking at a bike of less than 15kg. Based on her height, she was recommended to consider an M frame size. She is not too fussy about technical characteristics such as number of gears or types of brakes!
Tim Saddle is a keen cyclist and would like to improve his performance when taking part in bike races. He is very specific in his requirements and is looking for a state of the art road bike with at least 27 gears, hydraulic brakes, disc brakes with a very light frame (<8 kg), 20 inches wheels and a large frame size (L). He has no limits on how much he can spend for this bike!
Ayaz Bearing is looking for an electric Mountain Bike to go mountain biking during the holidays. He would like a Crossbar frame with at least 21 gears. He is not too sure about the size so would like to find out if you have any bike in stock with either an L frame or XL frame.
Nikky Helmet is looking for either a mountain bike or hybrid bike to go through cycling paths in the forest. She is looking for an L frame, low-step frame and would like the bike to be fitted with hydraulic brakes.
Fred Tyre works in the city and is commuting to work everyday by bike. He is looking for a hybrid e-bike (electric). He needs an M frame with hydraulic disc brakes and has a budget of £500 to £700.
Hamza Chainstay is looking for a road bike, with a crossbar frame size M and wheels of 24, 26 or 27 inches. He would like the bike to weight no more than 12kg.
Joe Crossbar is looking for a mountain bike, with a crossbar frame size M or L. He would like hydraulic brakes but does not want the bike to be fitted with disc brakes. He is not interested in electric bikes.
Lin Dynamo is looking for an electric hybrid bike to commute to work every day. She would like a low-step frame but is not too sure of the size she needs. She would like to see if you have either an S or an M frame in stock. She would also like to spend less than £600 on her bike.
Marek Hubcap would like a road bike within a budget of £200 to £300 and at least 24 gears. He would like to have disc brakes and a light frame e.g. less than 10 kg.
Anna Fork would like a non-electric mountain bike, frame M with 21 or 24 gears, hydraulic and disc brakes. She has a budget of £300 to £400 for this bike.























