MONTY HALL PYTHON HELP

This program simulates Monty Hall game

Program P4.25

by

April 20, 2015

Pseudo code:

- get the the number of trials

- do the following for number of trials

- ask the user to select a door

- place the car behind a door

- determine which door to open (a door which is

not selected by the user and does not have the car behind

- ask the user to stay or switch

- determine if the user wins a car

- display the result

- update the stats

- display summary

from random import randint

main program

def main() :

LOOSE = 0
WIN = 1
STAY = 1
SWITCH = 2
numStayWins = 0
numSwitchWins = 0

numTrials = int(input("How many runs?: "))
for i in range(numTrials) :
    carDoor = randint(1,3)     #Door number
    userDoor = askUserToSelect()   # Door number
    openDoor = doorOpener(carDoor, userDoor)  #Door number
    userChoice = askUsertoSwitchOrStay()   # Returns 1 for STAY, 2 for SWITCH
    winOrLoose = findResult(carDoor, userDoor, userChoice)  # Returns 1 for win, 0 for Loss
    updateStats()

displayResults(numTrials, numStayWins, numSwitchWins)

def updateStats() : return 2 # just a stub

def doorOpener(carDoor, userPick) : openedDoor = 1 return openedDoor

def findResult(carNum, userNum, switchOrStay) : result = 1 return result

def askUsertoSwitchOrStay() : decision = 1 return decision

This function asks the user to select a door

@parameters : None

@return: the id of the door that is selected by the user

def askUserToSelect() : doorNum = int(input("Please select a door number between 1 and 3: ")) if doorNum < 1 or doorNum > 3: print ("Wrong number, please select a umber between 1 and 3!") doorNum = int(input("Please select a door number between 1 and 3:")) return doorNum

def displayResults(numTrials, numStayWins, numSwitchWins) : return 5

main()

/r/Python Thread Parent