Question: Turtle Races In this lab we are going to work step by step through the problem of racing turtles. The idea is that we want
Turtle Races
In this lab we are going to work step by step through the problem of racing turtles. The idea is that we want to create two or more turtles and have them race across the screen from left to right. The turtle that goes the farthest is the winner.
There are several different, and equally plausible, solutions to this problem. Lets look at what needs to be done, and then look at some of the options for the solution. To start, lets think about a solution to the simplest form of the problem, a race between two turtles. Well look at more complex races later.
When you are faced with a problem like this in computer science it is often a good idea to find a solution to a simple problem first and then figure out how to make the solution more general.
Here is a possible sequence of steps that we will need to accomplish:
1. Import the modules we need
2. Create a screen
3. Create two turtles
4. Move the turtles to their starting positions
5. Send them moving across the screen
To fill in code for step 5, you may create a for loop using something like 150 or 200 as the range parameter. Then inside the for loop move each turtle forward using a random number as the parameter to forward.
import turtle
import random
wn = turtle.Screen() # 2. Create a screen
wn.bgcolor('lightblue')
lance = turtle.Turtle() # 3. Create two turtles
andy = turtle.Turtle()
lance.color('red')
andy.color('blue')
lance.shape('turtle')
andy.shape('turtle')
andy.up() # 4. Move the turtles to their starting point
lance.up()
andy.goto(-100,20)
lance.goto(-100,-20)
#step 5: send the two turtles moving across the screen
#copy and paste your code for option 3 here
wn.exitonclick()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
