-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurtleRace
More file actions
47 lines (37 loc) · 1.23 KB
/
Copy pathTurtleRace
File metadata and controls
47 lines (37 loc) · 1.23 KB
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
46
from turtle import Turtle, Screen
import random
dodo = Turtle()
screen = Screen()
screen.setup(750, 500)
user_bet = screen.textinput("Make your bet", "Which turtle will win the race?")
print(user_bet)
#make a color array
COLORS = ["red", "blue", "green", "yellow", "purple", "pink"]
y_position = [-70, -40, -10, 20, 50, 80]
turtles = []
#make the turtles
for i in range(0,6):
dodo = Turtle(shape = "turtle")
dodo.color(COLORS[i])
dodo.penup()
dodo.goto(-300, y_position[i])
turtles.append(dodo)
is_race_on = True
winner_color = None
while is_race_on:
for turtle in turtles:
#move forward randomly
turtle.forward(random.randint(1,10))
if turtle.xcor() >= 300:
is_race_on = False
winner_color = turtle.pencolor()
announcer = Turtle()
announcer.hideturtle()
announcer.penup()
announcer.goto(-100,100)
if user_bet == winner_color:
announcer.write(f"You won! The {winner_color} turtle won the race", "center", font = ("Arial", 16,))
else:
announcer.write(f"You lost! The {winner_color} turtle won the race", "center", font = ("Arial", 16,))
break
screen.exitonclick()