Python |在user_input之后停止/重新启动脚本 [英] Python | Stopping/Restarting a script after user_input
本文介绍了Python |在user_input之后停止/重新启动脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就在我问这个问题之前,我想说我对Python很陌生,所以我要问的可能很简单。
Just before I ask the question I would like to say that I am very new to Python so what ever I ask might be simple to do.
我的问题是这个:如何在这个问题得到解答后停止脚本。
My question is this: How do I stop the script after this question has been answered.
s1 = input("Is your phone freezing/stuttering? ")
if s1 == "Yes" or s1 == "yes":
print("Try deleting some apps and this might help with your problem")
if s1 == "No" or s1 == "no":
def foo():
while True:
return False
所以我真正想要的是当用户回复是时我希望解决方案出现并且脚本停止或者甚至可能重启。
So what I exactly want here is when the user replies with 'Yes' I want the solution to come up and the script to stop or if possible even restart.
推荐答案
可以通过此方式轻松退出。
A simple exit could be reach by this.
我还使用了较低的功能所以它会看起来更加pythonic
I also used the lower function so it will look a bit more pythonic
只需一个简单的循环:
s1 = "yes"
while s1 == "yes":
s1 = input("Is your phone freezing/stuttering? ").lower()
祝你好运!
这篇关于Python |在user_input之后停止/重新启动脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文