-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathturtle_winner.py
More file actions
executable file
·69 lines (57 loc) · 1.31 KB
/
turtle_winner.py
File metadata and controls
executable file
·69 lines (57 loc) · 1.31 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
#!/usr/bin/env python3
# Naz-Al Islam
# 05/02/16
# Prints which turtle wins the race
import turtle
t = turtle.Turtle()
wn = turtle.Screen()
wn.setup(400, 500)
wn.bgcolor("lightgreen")
wn.screensize(400, 500)
wn.setworldcoordinates(0, 0, 400, 500)
t.penup()
t.goto(0, 350)
t.pendown()
t.forward(400)
tess = turtle.Turtle()
tess.color("purple")
tess.penup()
tess.forward(100)
tess.pendown()
tess.left(90)
tess.forward(10)
alex = turtle.Turtle()
alex.color("blue")
alex.penup()
alex.forward(200)
alex.pendown()
alex.left(90)
alex.forward(10)
def h1():
tess.forward(50)
if tess.pos()[1] >= t.pos()[1]:
wn.bye()
print('TESS')
def h2():
alex.forward(50)
if alex.pos()[1] >= t.pos()[1]:
wn.bye()
print('ALEX')
wn.onkey(h1, 't')
wn.onkey(h2, 'a')
def handler_for_tess(x, y):
wn.title("Tess clicked at {0}, {1}".format(x, y))
tess.forward(50)
if tess.pos()[1] >= t.pos()[1]:
wn.bye()
print('TESS')
def handler_for_alex(x, y):
wn.title("Alex clicked at {0}, {1}".format(x, y))
alex.forward(50)
if alex.pos()[1] >= t.pos()[1]:
wn.bye()
print('ALEX')
tess.onclick(handler_for_tess)
alex.onclick(handler_for_alex)
wn.listen()
wn.mainloop()