CoderDojo turtle racing – 4 – countdown timer

1 Comment

To make this race more realistic, lets give our turtle a countdown timer so he knows when to start!

Find the following lines in the bumpy top example.

# start
start = time.time()

And replace them with these lines so that the turtle knows when to start.

# count down to start
for countdown in ["5","4","3","2","1"]:
  scorer.write("Time to start " + countdown,font=f)
  time.sleep(1)
  scorer.clear()
start = time.time()

The “for” command creates a loop in the code which can save a lot of time. All the indented lines after the “for” command are run for each different value of “countdown”. The list [“5″,”4″,”3″,”2″,”1”] is all the different values of countdown.

Once you have that working, you can try replacing [“5″,”4″,”3″,”2″,”1”] with [“ready”,”set”,”go”].

NEXT: Try creating your own track!

Categories: CoderDojo

One Reply to “CoderDojo turtle racing – 4 – countdown timer”

Comments are closed.