我编写了以下代码,如果 else 语句为真,我希望程序关闭。我是 python 新手,遇到了一些麻烦
password = raw_input('Enter yes to continue:')
if password == 'yes':
print'You have chosen to continue'
else:
print'You have chosen to exit'
将此添加到您的代码中
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()
import sys
if condition is true:
pass
# or your operating row.
else:
sys.exit()