-3

我编写了以下代码,如果 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'
4

2 回答 2

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()
于 2013-04-28T15:16:20.637 回答
0
import sys

if condition is true:
    pass
    # or your operating row.
else:
    sys.exit()
于 2013-04-28T15:20:19.720 回答