Today, I explored a fun Python project where I built a simple turtle racing game using the turtle graphics module. The program asks the user how many racers they want, sets up a race track, creates colorful turtle racers, and then lets them race upward until one crosses the finish line. The winning turtle’s color is printed at the end.
def get_number_of_racers():
^This function handles user input. It repeatedly asks the user for a number between 2 and 10, checks whether the input is numeric, and only returns once the user gives a valid number. It prevents invalid or out‑of‑range values so the rest of the program runs smoothly.
def create_turtles(colors):
^This function is responsible for creating the turtle racers. It spaces them evenly across the screen, sets their color and shape, points them upward, and positions them at the starting line. Each turtle is stored in a list so the race function can move them later.
def race(colors):
^This function runs the actual race. It loops forever, moving each turtle forward by a random distance between 1 and 20. After each move, it checks whether a turtle has reached the top of the screen. As soon as one crosses the finish line, the function returns the color of the winning turtle.


Leave a Reply