Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
87 lines (71 loc) · 1.96 KB
/
Copy pathmain.py
File metadata and controls
87 lines (71 loc) · 1.96 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from turtle import Turtle, Screen
tim=Turtle()
screen=Screen()
def move_forward():
tim.forward(10)
def move_backward():
tim.backward(10)
def move_left():
#using heading function to colect the orientation
x=tim.heading()
#setheading function to get orientation each clicking turn
tim.setheading(x+10)
def move_right():
x=tim.heading()
tim.setheading(x-10)
def clear():
tim.reset()
#su dung listen in turtle to create moving using arrows
#moving c
screen.listen()
screen.onkey(key="w" ,fun=move_forward)
screen.onkey(key="s" ,fun=move_backward)
screen.onkey(key="a",fun=move_left)
screen.onkey(key="d",fun=move_right)
screen.onkey(key="c",fun=clear)
screen.exitonclick()
#xin chao day la chao day
#change git repo direction
#create a Turtles race using Turtle
from turtle import Turtle,Screen
screen=Screen()
screen.setup(width=500,height=400)
user_bet=screen.textinput(title="Make your bet", prompt="Which turtle will win the race ? Enter a color")
Turtles=[]
for turtle in range(5):
turtle=Turtle()
turtle.shape("turtle")
Turtles.append(turtle)
colors=["red","green","blue","pink","black"]
default=100
for i in range(len(Turtles)):
Turtles[i].color(colors[i])
Turtles[i].penup()
Turtles[i].goto(-230,default)
Turtles[i].pendown()
default-=50
if user_bet :
is_race_on=True
import random
distance=0
while is_race_on:
for i in range(len(Turtles)):
random_step=random.randint(1,10)
Turtles[i].forward(random_step)
Turtles[i].clear()
distance+=10
if distance==1000:
is_race_on=False
Max=float(0)
for i in range(len(Turtles)):
pros=Turtles[i].pos()
if pros[0] > Max :
Max=pros[0]
for i in range(len(Turtles)):
pros=Turtles[i].pos()
if Max==pros[0]:
if user_bet==Turtles[i].pencolor():
print("You win !")
else:
print(f"You loose, the winning turtle is {Turtles[i].pencolor()}")
screen.exitonclick()