### Project 7: Making Decisions

In project 7 you will implement a version of the game show, “Let's Make a Deal.” Your version of the game show is famous because it demonstrates the Monty Hall paradox.

#### Exercises

Turn in exercises 27, 28, 29, 30 and 31 with this project.

#### The Monty Hall Problem

The game show starts with three doors. Behind one of them is a car. Behind the other two are goats. Monty asks you to choose a door. For argument's sake let's say you choose door #1. Then Monty opens a different door to reveal a goat.

Monty then asks you, “would you like to keep the door you chose or switch doors?” The problem is a paradox because most people (even some with a Ph.D.) think that the odds of guessing right are 50/50. They're not, you have better odds if you switch.

### Getting Random Numbers

There are two kinds of random numbers on a computer. Random numbers that are good for things like games and random numbers that are good for cryptography. Cryptographic random numbers are so random it's very difficult to guess them, but they take time to generate. The `random`

package has random numbers that are good for games.

Here's how to get a random number between 1 and 3 (including 1 and 3):

import random my_number = random.randrange(1, 4)

Use this code to generate the number of the door with a car behind it. You should assume that the other doors have the goats.

### Game Procedure

Your game starts by picking a random number (the number of the door with the car). Then prompt the user for the first guess.

Pick a door:

You program has to determine what Monty's guess will be. There are rules that govern Monty's guess:

- Monty will always pick a goat.
- If the contestant picked a door with a car behind it Monty may open any other door.
- If the contestant picked a door with a goat behind it Monty will open the door with the other goat.

You will need nested if/elif/else statements to determine Monty's pick. Once Monty decides make Monty's choice known:

Monty opens door #3

Prompt the user if they wish to stay or switch.

Do you wish to stay or switch:

The user must type “stay” or “switch” you don't have to worry about incorrect input. After the second choice reveal whether the user won the car or won the goat.

You won the car!

Test your game thoroughly. While you're developing the game it's a good idea to print out the door that the car is behind so you can verify that it works.

### Required Functions

Your program is required to have the following functions:

`pick_random_door`

- No arguments
- Returns:
**BOOLEAN**door1 -`True`

if the car is behind door 1 otherwise`False`

.**BOOLEAN**door2 -`True`

if the car is behind door 2 otherwise`False`

.**BOOLEAN**door3 -`True`

if the car is behind door 3 otherwise`False`

.- Note: Only one of the return values should be true!

`montys_choice`

- Arguments:
**BOOLEAN**`True`

if the car is behind door 1**BOOLEAN**`True`

if the car is behind door 2**BOOLEAN**`True`

if the car is behind door 3**INTEGER**The number of the door that was guessed by the contestant

- Returns:
**INTEGER**Monty's choice of a door

`has_won`

- Arguments:
**BOOLEAN**`True`

if the car is behind door 1**BOOLEAN**`True`

if the car is behind door 2**BOOLEAN**`True`

if the car is behind door 3**INTEGER**The number of the door that was guessed by the contestant**BOOLEAN**`True`

if they contestant wants to switch doors,`False`

if they want to stay.

- Returns
`True`

if the contestant won the car,`False`

if they won a goat.

Each function should have a docstring describing what it does.

### Requirements

- You must have a docstring describing your program.
- You must have the required functions
- The functions must have the exact names as above
- The functions must take the exact arguments in the order above
- The functions must have docstrings.

- The program must say “car” if you win and “goat” if you lose.
- All code should be in a function
- Put the game input and print functions in
`main()`

- Your program must be submitted in a file called
`project7.py`

### Starter Code

Sart with the following code. It shows the outline of game play:

import random def main() : door1, door2, door3 = pick_random_door() guess = int(input('Pick a door: ')) monty = montys_choice(door1, door2, door3, guess) print ('Monty opens door #{}'.format(monty)) choice = input ('Do you switch or stay: ') if choice == 'switch' : switch = True else: switch = False if has_won(door1, door2, door3, guess, switch) : print ('You win the car!') else: print ('You win a goat.') if __name__ == '__main__' : main()

### Advanced

The downloadable code for this week contains a stub for playing the Let's Make a Deal game using the web. Add the required functions from above and complete the game play. Note that the templates contain `if`

statements.

Requirements for the advanced version:

- You must have a docstring describing your program
- You must have the required functions from the assignment
- The functions must have the exact names
- They must take the same arguments and return the same values

- Your program must be submitted in a file called
`project7_adv.py`

- You must have the same directory layout as the download
`templates`

- Your HTML templates go here (you can name them anything you like)

`resources`

- The images must go here (you can rename them or change them if you like)

### Grading

- 5 points for the exercises
- 5 points for a correct submission
- 10 points for the correctness of your program.