Python 2.7退出

use*_*562 0 python quit

我已添加此功能,以确保用户实际上想要退出该程序.当你真的想要退出时它可以工作但是如果你想返回程序它只是循环语句:

def WantToQuit():
    Quit = raw_input("Please enter y if you are sure you want to quit, if not press n to return ")
    if Quit == 'y':
        print ('')
    elif Quit == 'n':
        DisplayMenu()
        return WantToQuit()
Run Code Online (Sandbox Code Playgroud)

别处:

elif Choice == 'q':
    WantToQuit()
    raw_input('Press enter key to continue ')
Run Code Online (Sandbox Code Playgroud)

ean*_*son 5

替换print ('')sys.exit (0)和删除return WantToQuit().

我还建议您.lower()Quit变量应用,以便它不区分大小写.