Exit shutdown function python
本问题已经有最佳答案,请猛点这里访问。
我已经编写了以下代码,如果else语句为真,我希望程序关闭。我对Python不熟悉,有点麻烦
1 2 3 4 5 | password = raw_input('Enter yes to continue:') if password == 'yes': print'You have chosen to continue' else: print'You have chosen to exit' |
1 2 3 4 5 6 7 | import sys if condition is true: pass # or your operating row. else: sys.exit() |
将此添加到代码中
1 2 3 4 5 6 | 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() |