title: How to return to the main menu in a loop?
body: <p>I'm wondering if this is the right approach to looping back to the main menu in python. After selecting a choice and completing a task, the script needs to return back to the main menu instead of exiting.</p>
  <pre><code>#!/usr/bin/python
  
  def mainmenu():
      print ('1. Scan')
      print ('2. Ping')
      print ('3. Exit')
      print
  
      choice = int(raw_input('&gt; Enter your choice: '))
  
      if choice == 1:
         print ('Starting Scan\n')
         mainmenu()
      elif choice == 2:
         print ('Starting Ping\n')
         mainmenu()
      elif choice == 3:
         print ('Exiting\n')
         exit(0)
  mainmenu()
  </code></pre>
  <p>This kind of works, but don't think it's the right way.</p>