-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathexercise_3.py
63 lines (58 loc) · 1.93 KB
/
exercise_3.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
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
#Three Button Monte
from button import Button
from graphics import GraphWin, Point, Text
from random import random
def main():
win = GraphWin("Three Button Monte", 500, 300)
win.setCoords(-12, -12, 12, 12)
win.setBackground("green3")
door1 = Button(win, Point(-7.5, -8), 5, 18, "Door 1")
door2 = Button(win, Point(0, -8), 5, 18, "Door 2")
door3 = Button(win, Point(7.5, -8), 5, 18, "Door 3")
direction = Text(Point(0, 10), "Pick a Door")
direction.draw(win)
x = random() * 3
pt1 = pt2 = pt3 = False
if 0 <= x <1:
pt1 = True
elif 1 <= x < 2:
pt2 = True
else:
pt3 = True
door1.activate()
door2.activate()
door3.activate()
click = win.getMouse()
while door1.clicked(click) or door2.clicked(click) or door3.clicked(click):
if door1.clicked(click):
if pt1 == True:
door1.update(win,"Victory!")
else:
if door2.clicked(click):
door2.update(win,"Correct Door.")
click = win.getMouse()
else:
door3.update(win,"Correct door.")
click = win.getMouse()
elif door2.clicked(click):
if pt2 == True:
door2.update(win,"Victory!")
else:
if door3.clicked(click):
door3.update(win,"Correct Door.")
click = win.getMouse()
else:
door1.update(win,"Correct door.")
click = win.getMouse()
else:
if pt3 == True:
door3.update(win,"Victory!")
else:
if door2.clicked(click):
door2.update(win,"Correct Door.")
click = win.getMouse()
else:
door1.update(win,"Correct door.")
click = win.getMouse()
win.getMouse()
main()