-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (30 loc) · 1.14 KB
/
main.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
import random
from turtle import Turtle, Screen
is_race_on = False
screen = Screen()
screen.setup(width=500, height=400)
user_bet = screen.textinput(title="Make your bet on Turtle race", prompt="Which color turtle are you gonna choose?:"
" in red,orange,yellow,green,blue,purple")
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
y_pos = [-70, -40, -10, 20, 50, 80]
all_turtles = []
for c in range(0, 6):
new_turtle = Turtle(shape="turtle")
new_turtle.color(colors[c])
new_turtle.penup()
new_turtle.goto(x=-230, y=y_pos[c])
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"You win! {winning_color} is the winner! 🐢🎉")
else:
print(f"You lost! {winning_color} is the winner! ")
rand_distance = random.randint(0, 10)
turtle.forward(rand_distance)
screen.exitonclick()