-
Notifications
You must be signed in to change notification settings - Fork 0
/
turtle_race.py
35 lines (30 loc) · 1.01 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
import random
from turtle import Turtle, Screen
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
screen = Screen()
screen.colormode(255)
screen.setup(width=500, height=500)
all_turtles = []
y = -100
for turtle_index in range(0, 6):
new_turtle = Turtle(shape="turtle")
new_turtle.color(colors[turtle_index])
new_turtle.penup()
new_turtle.goto(-240, y)
all_turtles.append(new_turtle)
y += 50
answer = screen.textinput(title="Turtle Race", prompt="Which turtle do you think will win? ")
if answer:
is_race_on = True
while is_race_on:
for each_turtle in all_turtles:
spaces = random.randint(0, 10)
each_turtle.forward(spaces)
if each_turtle.xcor() >= 230:
winner = list(each_turtle.color())[0]
if answer == winner:
print(f"YOU WIN! The winner is {winner}.")
else:
print(f"YOU LOSE! The winner is {winner}.")
is_race_on = False
screen.exitonclick()