-
Notifications
You must be signed in to change notification settings - Fork 1
/
Turtle_race.py
45 lines (30 loc) · 1.11 KB
/
Turtle_race.py
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
43
44
45
from turtle import Turtle,Screen
import random
screen=Screen()
screen.setup(width=500,height=400)
is_race_on=False
colours=["red","blue","yellow","green","orange","pink"]
user_bet=screen.textinput(title="Make your bet",prompt="Which Turtle will win the race? Choose color: ")
all_turtles=[]
x=-230
y=[-70,-40,-10,20,50,80]
for i in range(len(colours)):
new_turtle=Turtle(shape="turtle")
new_turtle.up()
new_turtle.goto(x,y[i])
new_turtle.color(colours[i])
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"Congratulations!!! {turtle.pencolor()} has won the race")
else:
print(f"{turtle.pencolor()} has won the race, You Loose")
rand_distance=random.randint(1,10)
turtle.forward(rand_distance)
screen.exitonclick()