#!/usr/bin/env python #montyhall.py #3 door monte simulation adapted into a Monty Hall problem #written by ALT 2008. from random import randint from graphics import * from door import Door from button import Button def main(): win = GraphWin("Three Door Monty", 640, 480) win.setCoords(0, 0, 20, 20) win.setBackground('white') title = Text(Point(10, 18), "3 Door Monty. Find Big Money and Big Prizes.") title.draw(win) Win = "Find the Prize" total = 0 choice = 0 prizeBox = Text(Point(10, 17), Win) prizeBox.draw(win) winnings = Text(Point(10, 16), total) winnings.draw(win) door1 = Door(win, Point(5, 10), 4, 8, "Door 1") door1.activate() door2 = Door(win, Point(10, 10), 4, 8, "Door 2") door2.activate() door3 = Door(win, Point(15, 10), 4, 8, "Door 3") door3.activate() quitButton = Button(win, Point(13, 3), 4, 2, "Quit") quitButton.activate() reset = Button(win, Point(7, 3), 4, 2, "Play Again") reset.activate() prize = randint(1,3) pt = win.getMouse() while not quitButton.clicked(pt): if door1.clicked(pt): choice = 1 elif door2.clicked(pt): choice = 2 elif door3.clicked(pt): choice = 3 if choice == prize: Win = "Hooray! Big Money & Big Prizes!" total = total + 1 elif choice != prize: Win = "So Sorry. Try Again." if reset.clicked(pt): Win = "Find the Prize" total = 0 winnings.setText(total) prizeBox.setText(Win) prize = randint(1,3) pt = win.getMouse() win.close() if __name__ == "__main__": main()