-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (44 loc) · 1.46 KB
/
Copy pathmain.py
File metadata and controls
51 lines (44 loc) · 1.46 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
47
48
49
50
51
from turtle import Turtle, Screen
import random
screen = Screen()
# def factor():
# its.forward(50)
# def backward():
# its.backward(50)
# def left_turn():
# head_direction= its.heading() + 10
# its.setheading(head_direction)
# def right_turn():
# head_direction = its.heading() - 10
# its.setheading(head_direction)
# screen.listen()
# screen.onkey(key="space", fun=factor)
# screen.onkey(key="q", fun=backward)
# screen.onkey(key="w", fun=left_turn)
# screen.onkey(key="e",fun=right_turn)
is_race_on = False
screen.setup(height=400, width=600)
user_bet = screen.textinput(title="who will win the race", prompt="which color you choose")
rainbow_color = ["red", "yellow", "green", "blue", "purple", "orange"]
y_position = [0, -62, -124, 62, 124, 180]
all_turtles = []
for turtle_index in range(0, 6):
its = Turtle(shape="turtle")
its.color(rainbow_color[turtle_index])
its.penup()
its.goto(x=-270, y=y_position[turtle_index])
all_turtles.append(its)
if user_bet:
is_race_on = True
while is_race_on:
for turtle in all_turtles:
if turtle.xcor() > 270:
is_race_on = False
winning_color = turtle.pencolor()
if winning_color == user_bet:
print(f"you won the {winning_color} turtle won ")
else:
print(f"you lost ! The {winning_color} turtle won")
random_distance = random.randint(0, 10)
turtle.forward(random_distance)
screen.exitonclick()