在python中运行特定函数后返回主屏幕

时间:2016-08-24 13:34:44

标签: python networking

所以我有一个程序,它有一个主菜单,你可以选择一个选项,然后根据所选的数字运行一个函数。

我想做的是在用户运行选项后,如果他们愿意,可以返回主菜单。以下是它的外观示例:

from module import submodule

def function1(x):
  do something
  return something

def function2(y):
  do something
  return something

def function3(z):
  do something
  return something

print "Welcome to this script. Please choose an option:\n"
print "\t [1] Do something crazy.\n"
print "\t [2] Do something crazier.\n"
print "\t [3] Do something insane.\n"

x = 0

while x == 0:
  r = raw_input("Type in your number to select an option.")
  if r == "1":
    x = raw_input()
    function1(x)
    x = 1
  elif r == "2":
    y = raw_input()
      function2(y)
      x = 1
  elif r == "3":
    z = raw_input()
      function3(z)
      x = 1
  else:
    print "That is not a valid option. Please try again.\n"

正如您所看到的,一旦其中一个功能运行,它就完成了。我喜欢它可以让用户选择如果他们想要回到主菜单。

0 个答案:

没有答案