title: Stopping a Python program when a def statement gives a specific result
body: <p>I am trying to create a task based on the Dragon Realm game in the Invent your Own Games with Python book. The original allows one choice to be made and uses functions to set up those choices. I am trying to allow two separate choices to be made but can't figure out how to stop the task after the first choice if the def statement gives a specific result, ie. if the first choice is the wrong choice then the user does not get to make a second choice. Any help would be much appreciated. Thanks.</p>
  
  <pre><code>import random
  import time
  
  def displayIntro():
      #introduction
  
  def chooseDoor():
      #user chooses door
  
  def checkDoor(chosenDoor):
      #checks user choice against random number
  
      if chosenDoor == str(friendlyDoor):
          #various good stuff happens
      else:
          #bad stuff happens
  
      #at this point I would like to go back to the option to play again if they have chosen the wrong door
      #but I can't make it work by putting a break here as it goes on to the next def statement (chooseBox)
      #this is where the original game finished
  
  def chooseBox():
  #user chooses a box but only if they made the correct choice above
  
  def checkBox(chosenBox):
  #checks user choice against random number and good or bad stuff happens
  
  playAgain = 'yes'
  while playAgain == 'yes' or playAgain == 'y':
  
  displayIntro()
  
  doorNumber = chooseDoor()
  
  checkDoor(doorNumber)
  
  boxNumber = chooseBox()
  
  checkBox(boxNumber)
  
  #play again option
  </code></pre>