2024-04-26 00:02:28 发布
网友
我正在使用Python3.2,并试图在用户输入他们不想继续的内容后退出它,是否有代码会在while循环中的if语句中退出它?我已经试过使用exit(),sys.exit(),sys.quit(),quit(),并提升SystemExit。
exit()
sys.exit()
sys.quit()
quit()
SystemExit
这对我很有用:
while True: answer = input('Do you want to continue?:') if answer.lower().startswith("y"): print("ok, carry on then") elif answer.lower().startswith("n"): print("sayonara, Robocop") exit()
编辑:在python 3.2中使用input,而不是raw_input
input
raw_input
这对我很有用:
编辑:在python 3.2中使用
input
,而不是raw_input
相关问题 更多 >
编程相关推荐