Skip to content

Commit 0f81d4f

Browse files
authored
turtle Racing project added
1 parent be3c8a7 commit 0f81d4f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Day19-Turtle/turtleRace.gif

2.7 MB
Loading

Day19-Turtle/turtleRace.mp4

4.27 MB
Binary file not shown.

Day19-Turtle/turtleRace.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from turtle import Turtle, Screen
2+
import random
3+
4+
s = Screen()
5+
s.setup(width=500, height=400)
6+
s.title("Turtle Race")
7+
s.bgcolor("black")
8+
9+
colors = ["green", "yellow", "white", "magenta", "orange", "red"]
10+
y_positions = [-120, -70, -20, 30, 80, 130]
11+
is_race_on = False
12+
all_turtles = []
13+
14+
for turtle_index in range(0, 6):
15+
new_turtle = Turtle(shape="turtle")
16+
new_turtle.penup()
17+
new_turtle.color(colors[turtle_index])
18+
new_turtle.goto(x=-230, y=y_positions[turtle_index])
19+
all_turtles.append(new_turtle)
20+
21+
user_bet = s.textinput(title="Turtle Race",
22+
prompt="Which turtle will u bet on? ")
23+
24+
if user_bet:
25+
is_race_on = True
26+
27+
28+
while is_race_on:
29+
for turtles in all_turtles:
30+
if turtles.xcor() > 230:
31+
is_race_on = False
32+
winning_color = turtles.pencolor()
33+
if winning_color == user_bet:
34+
print(f"\nYou've won. The {winning_color} turtle is the winner")
35+
else:
36+
print(f"\nYou've lost. The {winning_color} turtle is the winner")
37+
38+
39+
random_distance = random.randint(1,10)
40+
turtles.fd(random_distance)
41+
42+
43+
s.exitonclick()

0 commit comments

Comments
 (0)