1
Home
Tirsvad edited this page 2026-11-15 13:43:15 +01:00

English · Dansk · Bahasa Melayu

Turtle Race

A turtle race game: bet on a colour and watch six turtles race.

What is it?

Day 19 of the Udemy course 100 Days of Code: The Complete Python Pro Bootcamp, on turtle races. A 500 by 400 window opens and asks for your bet: the colour of the turtle you think wins (red, orange, yellow, green, blue or purple). Six turtles line up on the starting line and race. In every round each turtle moves a random distance of 0 to 10 steps, and the first turtle to pass the finish line (x = 230) wins. The terminal then tells you who won and whether your bet was right. The names of the lectures are kept where they exist (screen, user_bet, all_turtles, new_turtle and is_race_on).

What the exercise teaches

  • Asking for input in the turtle window and normalising the answer
  • Creating several turtles in a loop and keeping them in a list
  • Moving each turtle a random distance with random.randint
  • Detecting the finish line by the x coordinate and finding the winner
  • Testing the game rules with fakes of the screen and the turtle and a seeded random generator, so no window opens

What it does

  • A bet on one of six colours; blanks and letter case do not matter
  • Six turtles on a starting line, racing in rounds of 0 to 10 steps each
  • A message that names the winner and says whether the bet won
  • No race starts if you cancel the prompt or type a colour that is not in the list
  • No runtime dependencies beyond the Python standard library

Next