import random from turtle import * def show_welcome(): setup(800, 600) bgcolor("forestgreen") color("white") penup() goto(0, 50) write("SHEEP IN JEEPS: THE GREAT DERBY", align="center", font=("Arial", 30, "bold")) goto(0, -50) write("Press OK to Start the Engines!", align="center", font=("Arial", 16, "italic")) textinput("Welcome", "Ready to play?") def setup_race_track(): clearscreen() bgcolor("forestgreen") penup() goto(300, 150) pendown() color("white") goto(300, -150) penup() def create_racers(names): racers = [] for i in range(6): t = Turtle("turtle") t.penup() t.color("white") t.name = names[i] t.goto(-350, 100 - (i * 50)) t.write(f"{t.name} ", align="right", font=("Arial", 10, "bold")) racers.append(t) return racers def run_race(racers): winner = "" while winner == "": if random.randint(1, 50) == 1: victim = random.choice(racers) victim.goto(-350, victim.ycor()) for t in racers: t.forward(random.randint(5, 15)) if t.xcor() > 300: winner = t.name return winner def update_money_display(money): """Helper to draw the current balance on the screen""" money_pen = Turtle() money_pen.hideturtle() money_pen.penup() money_pen.color("yellow") money_pen.goto(-380, 260) money_pen.write(f"Wallet: ${money}", font=("Arial", 18, "bold")) def show_final_screen(money): clearscreen() bgcolor("black") color("yellow") penup() goto(0, 0) if money >= 500: write("YOU ARE RICH! GAME OVER", align="center", font=("Arial", 24, "bold")) else: write("BANKRUPT! GAME OVER", align="center", font=("Arial", 24, "bold")) def main(): names = ["Fred", "Alice", "Max", "Xin", "Brad", "Jeff"] money = 100 show_welcome() while 0 < money < 500: setup_race_track() racers = create_racers(names) update_money_display(money) bet = textinput(f"Wallet: ${money}", f"Who wins? {names}") winner = run_race(racers) if bet and winner.lower() == bet.lower(): money += 50 msg = f"{winner} won! You earned $50. Total: ${money}" else: money -= 30 msg = f"{winner} won. You lost $30. Total: ${money}" textinput("Race Over", f"{msg}\n\nClick OK for next round.") show_final_screen(money) done() main()