-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay-19
42 lines (34 loc) · 1.16 KB
/
Day-19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from turtle import Turtle, Screen
import random
is_race_on = False
screen = Screen()
screen.bgcolor("black")
screen.setup(width=500,height=400)
user_bet = screen.textinput(title="Make your bet", prompt="Which turtle will win the race? Enter the color: ")
colours = ["red","blue","green","pink","purple","yellow"]
current = -120
all_turtles = []
def change_coordinate():
global current
current += 30
return current
for turtle_index in range(6):
new_turtle = Turtle(shape="turtle")
new_turtle.penup()
new_turtle.color(colours[turtle_index])
new_turtle.goto(x=-240, y=change_coordinate())
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_colour = turtle.pencolor()
if winning_colour == user_bet:
print(f"You've won! The {winning_colour} turtle is the winner.")
else:
print(f"You've lost! The {winning_colour} turtle is the winner.")
random_distance = random.randint(0, 10)
turtle.forward(random_distance)
screen.exitonclick()