1. # This program will simulate a sequence from the game show Let's Make A Deal,
  2. # which is often called "The Monty Hall Problem"
  3.  
  4. import random
  5. import time
  6.  
  7. def displayIntro():
  8. print('Hi, and welcome to Let\'s Make A Deal. I\'m your host, Monty Hall')
  9. time.sleep(2)
  10. print('Let\'s meet our contestant for today\'s show. What\'s your name?')
  11. name = input()
  12. print('Great to have you here ' + name)
  13. time.sleep(1)
  14. print('Tell us a little about yourself')
  15. input()
  16. print('That\'s fantastic. Let\'s get started with the game')
  17. print()
  18. time.sleep(2)
  19. print('There are three doors next to me. Behind one of these doors is a brand new car! The other two doors have... less glamorous prizes')
  20. print()
  21. time.sleep(2)
  22. print('You get to choose a door and win a prize!')
  23.  
  24. def firstChoice():
  25. print('Which door will you take: Door Number 1, Door Number 2, or Door Number 3?')
  26. print('Type 1 2 or 3 to make your choice')
  27. choice = input()
  28. while choice != '1' and choice != '2' and choice != '3' :
  29. print('Take some time, think it over, and make your choice. 1 2 or 3')
  30. choice = input()
  31. if choice in [1, 2, 3]:
  32. choice = int(choice)
  33. return choice
  34.  
  35. def MontyOpensDoor(chosenDoor, doorList, carDoor):
  36. print('Okay, you\'ve made your choice. Are you certain about that though?')
  37. print()
  38. time.sleep(2)
  39. print('Maybe you\'d like to change your mind.')
  40. print()
  41. time.sleep(2)
  42. print('Tell you what, I\'ll open up one of those other two doors.')
  43. print()
  44. time.sleep(2)
  45. del doorList[chosenDoor - 1]
  46. if chosenDoor == carDoor:
  47. switch = False
  48. montyOpens = random.randint(0,1)
  49. openDoor = doorList[montyOpens]
  50. del doorList[montyOpens]
  51. doorRemaining = doorList[0]
  52. else:
  53. switch = True
  54. montyOpens = random.randint(0,1)
  55. if doorList[montyOpens] == carDoor:
  56. del doorList[montyOpens]
  57. openDoor = doorList[0]
  58. else:
  59. openDoor = doorList[montyOpens]
  60. doorRemaining = carDoor
  61.  
  62. print('Okay, let\'s open up door number ' + openDoor +'...')
  63. print()
  64. time.sleep(5)
  65. print('There\'s a goat behind there!')
  66. print()
  67. time.sleep(2)
  68. print('So would you like to switch to door number' + doorRemaining + ' , or stick it out with door number ' + chosenDoor + '?')
  69. return switch
  70.  
  71. def switchDoor(switch):
  72. print('Type s to switch')
  73. choice = input()
  74. if choice == 's':
  75. choice = True
  76. if choice != 's':
  77. choice = False
  78.  
  79. print('Okay, let\'s see what you\'ve won...')
  80. print()
  81. time.sleep(2)
  82. print()
  83. time.sleep(2)
  84. if switch == choice:
  85. print('Congratulations, you\'ve won a new car!')
  86. print('Thanks for playing')
  87.  
  88. if switch != choice:
  89. print('Oooh, too bad. You\'ve won a goat. I guess you can let it keep your lawn trimmed?')
  90. print('Thanks for playing')
  91.  
  92.  
  93. playAgain = 'yes'
  94.  
  95. displayIntro()
  96. while playAgain:
  97. door = [1, 2, 3]
  98. choice = firstChoice()
  99. carDoor = random.randint(1,3)
  100. switchResult = MontyOpensDoor(choice, door, carDoor)
  101. switchDoor(switchResult)
  102. time.sleep(3)
  103. print()
  104. print('Would you like to play again?')
  105. playAgain = input().lower().startswith('y')
  106.