def test_that_selecting_invalid_door_raises_correct_exception(): game = MontyHallGame() try: game.select_door(4) except InvalidGameInput: pass
def test_that_game_wins_or_loses(): game = MontyHallGame() game.select_door(1) game.let_host_open_door() to_open = random.choice(game.available_doors()) game.select_door(to_open) won = game.open_door() assert won or not won
def test_that_statistics_returns_str(): # Produce some testdata first for i in range(10): test_that_normal_game_wins_or_loses() assert (type(MontyHallGame.statistics()) == str)
def test_that_statistics_returns_str(): # Produce some test data first for i in range(10): test_that_game_wins_or_loses() # Check that the statistics function produces a string assert (type(MontyHallGame.statistics()) == str)
def statistics(): stats = MontyHallGame.statistics().replace("\n", "</br>") return "<h1>Statistics</h1>{}".format(stats)
def new(): game_id = str(uuid.uuid4()) game = MontyHallGame() games[game_id] = game return render_template("select.html", game_id=game_id)
#!/usr/bin/env python from monty_hall_game import MontyHallGame while True: print("\n\nWelcome to a new Monty Hall game") print("******************************\n") game = MontyHallGame() door = int(input("Select a door between 1-3: ")) game.select_door(door) door = game.let_host_open_door() print("The host opens door {}.".format(door)) a = game.available_doors() door = int( input( "Which door would you like to open (choose from {}): ".format(a))) game.select_door(door) won = game.open_door() if won: print("Congratulations! You have won!") else: print("I am sorry! You have lost.") print("\n---------------") print("Game statistics")