-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturtle_race.py
More file actions
35 lines (31 loc) · 842 Bytes
/
turtle_race.py
File metadata and controls
35 lines (31 loc) · 842 Bytes
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
from turtle import Turtle, Screen
import random
screen = Screen()
screen.setup(500, 400)
user_bet = screen.textinput("Make your bet", "which one win???")
colors = ["red", "orange", "green", "blue", "yellow", "purple"]
all_t = []
is_race_on = False
win = ""
print(user_bet)
for index in range(0, 6):
tim = Turtle(shape="turtle")
tim.penup()
tim.color(colors[index])
y = index * 30
tim.goto(-230, 90 - y)
all_t.append(tim)
if user_bet:
is_race_on = True
while is_race_on:
for tur in all_t:
if tur.xcor() > 230:
win = tur.pencolor()
if win == user_bet:
print("win")
else:
print(f"lose, win is {win}")
is_race_on = False
rand_distance = random.randint(0, 10)
tur.forward(rand_distance)
screen.exitonclick()