2016-12-14 3 views
-1

У меня есть проблема с моим питон скрипт, как когда приходит этот вопрос до:Python | Пропуск user_input

("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 
+3

'def foo(): while True: return False' Как вы думаете, что это делает? –

+0

использовать 'if ..... elif' вместо двух' if ... if' или даже 'if ... else' – depperm

ответ

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» там.)

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.")