Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. from random import randint
  2.  
  3. def part1():
  4. car = randint(1,3)
  5. guess = input('What door would you like to pick: ')
  6. #print('The car was behind door #' + str(car) + "!")
  7.  
  8. def part2():
  9. car = randint(1,3)
  10. guess = input('What door would you like to pick: ')
  11. guess = int(guess)
  12.  
  13. if car == 1 and guess == 1:
  14. print('There is a goat behind door 2')
  15. if car == 2 and guess ==2:
  16. print('There is a goat behind door 3')
  17. if car == 3 and guess == 3:
  18. print('There is a goat behind door 1')
  19.  
  20. if (car == guess):
  21. des = raw_input('Would you like to change your pick? ')
  22. if (des == 'yes'):
  23. guess = (guess+1) % 3
  24.  
  25. if guess == car:
  26. print('You won!')
  27. else:
  28. print('The car was behind door #' + str(car) + '!')
  29. print('You lost!')
  30.  
  31.  
  32. def part3():
  33. rounds = input('How many rounds of the game should be simulated: ')
  34. while (rounds < 10 or rounds > 10000):
  35. print('Must enter a number between 10 and 10000')
  36. rounds = input('Please try again: ')
  37.  
  38. action = raw_input('Should the player switch or stay: ')
  39.  
  40. while(action != 'switch' and action != 'stay'):
  41. print('Must enter either switch or stay')
  42. action = raw_input('Please try again: ')
  43.  
  44.  
  45. won_games = 0;
  46. for i in range(rounds):
  47. car = randint(1,3)
  48. guess = randint(1,3)
  49.  
  50. if (car == guess):
  51. if (action == 'switch'):
  52. guess = (guess+1) % 3
  53.  
  54. if guess == car:
  55. won_games +=1
  56.  
  57. percentage = 1.0*(won_games)/rounds #convert to float and get percentage
  58. percentage = "{0:.0%}".format(percentage) #format into a percentage
  59. print('The player won ' + str(won_games) + '/' + str(rounds) + ' games (' + str(percentage) + ')!')
  60.  
  61.  
  62.  
  63.  
  64. part3()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement