title: Python call function again if incorrect input
body: <p>I am fairly new to Python, I am just wondering what the best way to do this (very simple question):</p>
  
  <p>I have a function that prompts the user to select an option, if the option they entered is not valid it will call the function again:</p>
  
  <pre><code>def choose_colour():
      print "Select colour:"
      print "1. Red"
      print "2. Blue"
      print "3. Green"
      selection = raw_input()
  </code></pre>
  
  <p>Initially I had an if statement comparing the input and IF it was an incorrect input I would call the function again within itself. Which is not practical and wrong.</p>
  
  <pre><code>def choose_colour():
      print "Select colour:"
      print "1. Red"
      print "2. Blue"
      print "3. Green"
      selection = raw_input()
  
      if selection == "1":
           colour = "Red"
      elif selection == "2":
           colour = "Blue"
      elif selection == "3":
           colour = "Green"
      else:
           print "Please select, 1, 2 or 3"
           choose_colour()
  </code></pre>
  
  <p>Edit: </p>
  
  <p>This works but I prefer the loop solution.</p>
  
  <pre><code>def set_TPL_colour():
      print "Enter TPL colour value:"
      print "1. WHITE"
      print "2. GREEN"
      print "3. AMBER"
      print "4. RED"
      print "&gt;&gt;&gt;",
      option = raw_input()
      if option == "1":
          tpl_colour = "WHITE"
          return tpl_colour
      elif option == "2":
          tpl_colour = "GREEN"
          return tpl_colour
      elif option == "3":
          tpl_colour = "AMBER"
          return tpl_colour
      elif option == "4":
          tpl_colour = "RED"
          return tpl_colour
      else:
          print "ERROR incorrect option selection"
          tpl_colour = set_TPL_colour()
          return tpl_colour
  </code></pre>