繁体   English   中英

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

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

在我问这个问题之前,我想说我对Python还是很陌生,所以无论问什么都可能很容易做到。

我的问题是:回答此问题后,如何停止脚本。

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

所以我在这里想要的是,当用户回答“是”时,我希望解决方案出现并且脚本停止,或者甚至重启。

一个简单的出口可能由此实现。

我还使用了较低的功能,因此它看起来会更pythonic

只需一个简单的循环:

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

祝好运 !

您可以做的是围绕它创建一个循环

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