守则。
如果我输入a/b/c/q
,则默认为sys.exit
我真的不知道为什么会这样做,所以任何建议都非常受欢迎。
import sys
print(' Option A ')
print(' Option B ')
print(' Option C ')
answer = input(' ').lower
if answer == 'a':
#code is here
sys.exit
if answer == 'b':
#more code is here
sys.exit
elif answer == 'c':
#more code here
sys.exit
elif answer == 'q':
print ("exit program')
sys.exit
任何帮助都会很棒! (我对python很新,版本3.5.1)
答案 0 :(得分:0)
你错过了缩进:
if answer == 'a':
#code is here
sys.exit
应该是:
if answer == 'a':
#code is here
sys.exit()
您还需要为其他if
和elif
执行此操作。
请注意,自()
以来添加exit
是一个函数,而不是sys
的属性。