-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturtle_race.py
More file actions
42 lines (33 loc) · 900 Bytes
/
turtle_race.py
File metadata and controls
42 lines (33 loc) · 900 Bytes
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
from turtle import Turtle, Screen
import random
screen=Screen()
screen.setup(1000,600)
user_input = screen.textinput(title="Make a guess", prompt="ENter a color :")
colors=["red","green","blue", "yellow"]
if user_input not in colors:
colors.append(user_input)
colors.remove("green")
final_tims=[]
for x in range(4):
new=Turtle()
new.shape("turtle")
a=random.choice(colors)
new.color(a)
colors.remove(a)
final_tims.append(new)
y=[200,100,-100,-200]
for x in range(4):
final_tims[x].penup()
final_tims[x].goto(x=-400,y=y[x])
is_race_on = True
while is_race_on:
for x in final_tims:
x.speed("fastest")
if x.xcor() >= 400:
is_race_on= False
if x.color()== user_input:
print("u won")
else :
print(" u lost")
x.forward(random.randint(0,10))
screen.exitonclick()