from graphics import * from button1 import Button from graphics import GraphWin, Point import random def main(): win = GraphWin("Three Button Monte") win.setCoords(0,0,10,10) door1 = Button(win,Point(2.5,2.5),3,2, "Door 1") door2 = Button(win,Point(5,5),3,3, "Door 2") door3 = Button(win,Point(7.5,7.5),3,2, "Door 3") door1.activate() door2.activate() door3.activate() quitButton = Button(win,Point(7,1), 3,2, "Quit") pt = win.getMouse() while not quitButton.clicked(pt): ans = random.randrange(1,4) door1 = 1 door2 = 2 door3 = 3 if door1 == ans and door1.clicked(pt) == True: text(Point(5,2) , "You win!") else: text(Point(5,2) , "You lose!") if door2 == ans and door2.clicked(pt) == True: text(Point(5,2) , "You win!") else: text(Pint(5,2) , "You lose!") if door3 == ans and door3.clicked(pt) == True: text(Point(5,2) , "You win!") else: text(Point(5,2) , "You lose!") quitButton.activate() pt = win.getMouse() win.close() main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question