Python |跳过user_input

时间:2016-12-14 14:10:37

标签: python user-input

我的python脚本出现问题,就像这个问题出现时一样:

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

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

("Is your phone freezing/stuttering? ")

所以,如果我回答是的话,如果我输入No,那么就会出现问题,那么我的硬件问题会出现,但我不希望这种情况发生。

这是我的剧本:

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

2 个答案:

答案 0 :(得分:0)

(1)想想如果条款做了什么。

(2)确保你理解python中的标签/空格。

以下是如何操作:

phone2 = input("Is there problem with the software or hardware? ") 
if phone2 == "Software" or phone2 == "software":
    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 phone2 == "Hardware" or phone2 == "hardware" :
   h1 = input("Does your phone switch on? ")
   if h1 == "No" or h1 == "no" :
      print("There might be a issue with your battery.")

答案 1 :(得分:0)

问题是您在if语句后没有使用正确的缩进,因此无论如何都会执行其余的代码:

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”功能。)