我编写了以下代码,如果else语句为true,我希望程序关闭。我是python的新手并且遇到了一些麻烦
password = raw_input('Enter yes to continue:')
if password == 'yes':
print'You have chosen to continue'
else:
print'You have chosen to exit'
答案 0 :(得分:0)
将此添加到您的代码中
import sys # This goes at the header
...
if password == 'yes'
pass # Your code goes on... I put the 'pass' just as a place holder
else
sys.exit()
答案 1 :(得分:0)
import sys
if condition is true:
pass
# or your operating row.
else:
sys.exit()