2016-12-14 73 views
-1

我有我的Python腳本中的問題,因爲當這個問題來了:Python |跳過USER_INPUT

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

當我輸入「軟件」我的第一個軟件問題來了

("Is your phone freezing/stuttering? ") 

所以,如果我回答是一個解決方案出現b'`ut如果我輸入否然後我的硬件問題出現,但我不希望這種情況發生。

這裏是我的腳本:

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:(我不認爲你需要那裏的「富」功能。)

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