CoderDojo turtle racing – 2 – oval track with scoring

1 Comment

This follows on from CoderDojo turtle racing – 1 – oval track. Copy your Python code from the first post and run it in this one. This time you will get a score showing how long it took your turtle to get around the track.

# Turtle racing track = oval track with score
# Don't edit the lines for turtle "track"
# Edit the lines for turtle "racer"
# between "# ninja start" and "# ninja end"
# See if you can find the fastest way around the track
# Make sure the turtle doesn't touch the sides

import turtle
import time

# turtle which draws track
track = turtle.Turtle()
track.speed(0)
track.color("black")
track.penup()
track.hideturtle()

# inside of track
track.goto(-50,-100)
track.pendown()
track.forward(100)
track.circle(100,180)
track.forward(100)
track.circle(100,180)
track.penup()

# outside of track
track.goto(-50,-150)
track.pendown()
track.forward(100)
track.circle(150,180)
track.forward(100)
track.circle(150,180)
track.penup()

# start / finish line
track.color("gray")
track.goto(20,-100)
track.pendown()
track.goto(20,-150)
track.penup()

# turtle which keeps score
scorer = turtle.Turtle()
scorer.color("blue")
scorer.speed(0)
scorer.penup()
scorer.goto(-170,170)
f=("Arial",15,"normal")

# turtle which races around track
racer = turtle.Turtle()
racer.shape("turtle")
racer.color("blue")
racer.speed(10)

# set up racer at start line
racer.penup()
racer.goto(0,-125)
racer.pendown()

# start
time.sleep(2)
start = time.time()

# ninja start


# PUT YOUR TURTLE RACER CODE HERE


# ninja end

#publish score
end = time.time()
scorer.write("Time (seconds) = "+str(end-start),font=f)

NEXT: CoderDojo turtle racing – 3 – bumpy top

Categories: CoderDojo

One Reply to “CoderDojo turtle racing – 2 – oval track with scoring”

Comments are closed.