退出关机功能python

问题描述:

我写了下面的代码,如果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() 
+0

现在我的代码看起来是这样的进口SYS 密码的raw_input =('输入yes继续:') #确定是否输入了输入。 如果密码==“是”: print'You选择了继续合“ 其他: print'You选择退出” sys.exit 我想Python程序关闭或至少互动窗口,但我没有得到结果,请帮助,我错过了什么?通过“关机”您意味着退出程序 – goat 2013-04-28 15:22:55

+0

?或者你的意思是别的吗? – Barranka 2013-04-29 03:54:08

+0

@MarkKearney我纠正了一个错字...而不是'sys.exit'它*必须*是'sys.exit()' – Barranka 2013-04-29 04:16:50

import sys 

if condition is true: 
    pass 
    # or your operating row. 
else: 
    sys.exit()