CoderDojo turtle racing – 3 – bumpy top

1 Comment

Here is a more difficult track. See if you can navigate your turtle all the way around the track without touching the sides of the track.

# Turtle racing track = bumpy top
# Don't edit the lines for turtles "track" or "scorer"
# 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,90)
track.forward(50)
track.circle(50,180)
track.circle(-50,180)
track.circle(50,180)
track.forward(50)
track.circle(100,90)
track.penup()

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

# start / finish line
track.color("gray")
track.goto(0,-100)
track.pendown()
track.goto(0,-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(-20,-125)
racer.pendown()

# start
start = time.time()

# ninja start


# YOUR CODE HERE


# ninja end

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

NEXT: CoderDojo turtle racing – 4 – countdown timer

Categories: CoderDojo

One Reply to “CoderDojo turtle racing – 3 – bumpy top”

Comments are closed.