蟒蛇|跳过 user_input [英] Python | Skipping a user_input

查看:32
本文介绍了蟒蛇|跳过 user_input的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当这个问题出现时,我的 python 脚本有问题:

I have a problem with my python script as when this question comes up:

("Is there problem with the software or hardware? ")

当我输入软件"时,我的第一个软件问题出现了

When I type in "Software" my first software question comes up

("Is your phone freezing/stuttering? ")

所以如果我回答是,就会出现一个解决方案,但是如果我输入否,那么我的硬件问题就会出现,但我不希望这种情况发生.

So if I answer yes a solution comes up b``ut if I type in No then my hardware question comes up but I dont want that to happen.

这是我的脚本:

phone2 = input("Is there problem with the software or hardware? ") #Question
if phone2 == "Software" or phone2 == "software" :
def foo():
 while True:
  return False
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
if phone2 == "Hardware" or phone2 == "hardware" :
    def foo():
     while True:
      return False
h1 = input("Does your phone switch on? ")
if h1 == "No" or h1 == "no" :
    print("There might be a issue with your battery. I recommend replacing          it with the help of a specialist")
if h1 == "Yes" or h1 == "yes" :
    def foo():
     while True:
        return False

推荐答案

问题是你在 if 语句之后没有使用正确的缩进,因此你的其余代码还是被执行了:

The problem was that you did not use proper indentations after your if statements ,hence the rest of your code was executed anyway:

phone2 = input("Is there problem with the software or hardware? ") #Question
if phone2 == "Software" or phone2 == "software" :
    def foo():
        while True:
             return False
    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
if phone2 == "Hardware" or phone2 == "hardware":
    def foo():
        while True:
            return False
    h1 = input("Does your phone switch on? ")
    if h1 == "No" or h1 == "no":
        print("There might be a issue with your battery. I recommend replacing it with the help of a specialist")
    if h1 == "Yes" or h1 == "yes":
        def foo():
            while True:
                return False

PS:(我认为你不需要那个foo"函数.)

PS: (I don't think you need that "foo" function in there.)

这篇关于蟒蛇|跳过 user_input的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆