Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle, Screen
- import random
- is_race_on = False
- screen = Screen()
- screen.setup(500, 400)
- user_bet = screen.textinput("Make your bet", "Which turtle will win the race? Enter a color: ").lower()
- print(user_bet)
- colors = ["red", "orange", "yellow", "green", "blue", "purple"]
- y_pos = [-70, -40, -10, 20, 50, 80]
- all_turtles = []
- for turtle_index in range(0, 6):
- new_turtle = Turtle(shape="turtle")
- new_turtle.color(colors[turtle_index])
- new_turtle.penup()
- new_turtle.goto(-230, y_pos[turtle_index])
- all_turtles.append(new_turtle)
- if user_bet:
- is_race_on = True
- while is_race_on:
- for turtle in all_turtles:
- if turtle.xcor() > 230:
- is_race_on = False
- winning_color = turtle.pencolor()
- if winning_color == user_bet:
- print(f"{winning_color} has won! You WIN! :)")
- else:
- print(f"{winning_color} Has won! You LOST! :(")
- rand_distance = random.randint(0, 10)
- turtle.forward(rand_distance)
- screen.exitonclick()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement