简体   繁体   English

Python | 在user_input之后停止/重新启动脚本

[英]Python | Stopping/Restarting a script after user_input

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. 在我问这个问题之前,我想说我对Python还是很陌生,所以无论问什么都可能很容易做到。

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. 一个简单的出口可能由此实现。

I also used the lower function so it will look a bit more pythonic 我还使用了较低的功能,因此它看起来会更pythonic

With just a simple loop: 只需一个简单的循环:

s1 = "yes"
while s1 == "yes":
  s1 = input("Is your phone freezing/stuttering? ").lower()

Good luck ! 祝好运 !

What you could do is create a loop around it 您可以做的是围绕它创建一个循环

x = 4
while x == 4:
    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
        break #<-- only if you want the program to end after false#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM