小编Epi*_*mic的帖子

结束Python脚本

在Python 3.2中,我正在编写一个基本菜单程序,当输入退出选项时,该功能没有结束.当选择退出时,它会结束脚本的其余部分所在的循环,并且应该终止脚本,但它不是,无论出于何种原因?我错过了一个杀死脚本的'end'函数,还是新的Python Shell只是错误?很确定这在Python 2.7中不是必需的.

import random
choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate blah\n(Q)uit\n>>>"))
while choice != "q" or choice != "Q":
    while choice != "i" and choice != "I" and choice != "c" and choice != "C" and choice != "q" and choice != "Q":
        print("Invalid menu choice.")
        choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate blah\n(Q)uit\n>>>"))
    if choice == "i" or choice == "I":
        print("blahblah.")
        choice = str(input("\nMenu:\n(I)nstructions\n(C)alculate blah\n(Q)uit\n>>>"))   
    if choice == "c" or choice == "C":
        x = int(input("Please enter the number of x: "))
        while …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

-1
推荐指数
1
解决办法
1104
查看次数

标签 统计

python ×1

python-3.x ×1