Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def part1():
- car = randint(1,3)
- guess = input('What door would you like to pick: ')
- #print('The car was behind door #' + str(car) + "!")
- def part2():
- car = randint(1,3)
- guess = input('What door would you like to pick: ')
- guess = int(guess)
- if car == 1 and guess == 1:
- print('There is a goat behind door 2')
- if car == 2 and guess ==2:
- print('There is a goat behind door 3')
- if car == 3 and guess == 3:
- print('There is a goat behind door 1')
- if (car == guess):
- des = raw_input('Would you like to change your pick? ')
- if (des == 'yes'):
- guess = (guess+1) % 3
- if guess == car:
- print('You won!')
- else:
- print('The car was behind door #' + str(car) + '!')
- print('You lost!')
- def part3():
- rounds = input('How many rounds of the game should be simulated: ')
- while (rounds < 10 or rounds > 10000):
- print('Must enter a number between 10 and 10000')
- rounds = input('Please try again: ')
- action = raw_input('Should the player switch or stay: ')
- while(action != 'switch' and action != 'stay'):
- print('Must enter either switch or stay')
- action = raw_input('Please try again: ')
- won_games = 0;
- for i in range(rounds):
- car = randint(1,3)
- guess = randint(1,3)
- if (car == guess):
- if (action == 'switch'):
- guess = (guess+1) % 3
- if guess == car:
- won_games +=1
- percentage = 1.0*(won_games)/rounds #convert to float and get percentage
- percentage = "{0:.0%}".format(percentage) #format into a percentage
- print('The player won ' + str(won_games) + '/' + str(rounds) + ' games (' + str(percentage) + ')!')
- part3()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement