2016-09-18 29 views
-2

下面的代碼是工作,直到我這一行下添加代碼:麻煩與我的故障排除指南

if questions=="phone not turning on": 

後,我添加的代碼下該行的代碼不再按預期工作。

print("Welcome to Bobby Dazler's trobleshooting for mobile phones. Please answer the questions concerning your issue with yes or no, unless specified to write something else. If your issue is none of these listed please enter other or don't know") 

solutions1="Place the phone into rice for 24 hours if this does not fix the issue please contact your manufacturer for a repair." 
solutions2="Check the battery is in correctly and attempt to charge the phone for atleast one hour, if this fails please contact your manufacturer." 
solutions3="Move to a different area, turn the phone on and off, if this fails please contact your service provider." 
solutions4="Turn the phone off silent mode, do this by either; manually going into the your phone's settings or use the buttons on the side of the phone to turn it off silent mode." 
solutions5="Use the buttons on the side of the phone to adjust the volume accordingly." 
solutions6="Contact your manufacturer to arrange a time to fix your cracked phone." 
solutions7="Delete some applications(apps) to make some more space for your phone." 
solutions8="Contact your manufacturer/insurance company to get your buttons replaced" 
solutions9="Charge your phone fully and hold down the button to attempt to turn it on, if this fails please contact your manufacturer to arrange for a repair." 
solutions10="Contact your manufacturer to fix your problem" 
solutions11="Reinsert the sim card and make sure the sim card is placed the right way upon entering the phone." 

print("cracked screen, phone not turning on, bad reception, phone doesn't ring, low volume, can't take photos or download applications, broken/missing buttons, sim card not working, water damage") 
questions = input("What problem are you having with your mobile phone? Please select one, please choose on the options and reply in a lower case") 


if questions== "cracked screen": 
     print(solutions6) 

if questions=="low volume": 
    print(solutions5) 

if questions=="phone not turning on": 
    print(solutions2) 
questions = input("Did that fix your issue?") 
if questions=="no" or "No": 
    print("Okay here's another solution") 
    print(solutions9) 
questions=input("Did that fix your issue?") 
if questions=="no" or "No": 
    print("Okay please try this") 
    print(solutions10) 

if questions=="bad reception": 
    print(solutions3) 

if questions=="phone doesn't ring": 
    print(solutions4) 

if questions=="can't take photos or download applications": 
    print(solutions7) 

if questions=="broken/missing buttons": 
    print(solutions8) 

if questions=="sim card not working": 
    print(solutions11) 

if questions=="water damage": 
    print(solutions11) 

else: 

    questions=input("Does the phone turn on?") 
    if questions=="Yes" or "yes": 
     print("Okay here is another question") 

    if questions=="No" or "no": 
     print(solutions10) 
+1

你能提供你所看到的錯誤? – alexbclay

+0

您可能希望閱讀關於Python [字典](https://docs.python.org/3/tutorial/datastructures.html#dictionaries)的內容,以便您不必混淆'if ...然後.... else' – dawg

+0

可能重複[如何測試一個變量對多個值?](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-多值) – MattDMo

回答

1

你的問題是,在這一部分:

if questions=="Yes" or "yes": 
    print("Okay here is another question") 

if questions=="No" or "no": 
    print(solutions10) 

變化if questions=="Yes" or "yes":爲其中之一:

  • if questions in ("Yes", "yes"):
  • if questions.lower() == "yes":
  • if questions=="Yes" or questions=="yes":

任何這些都可以。

x or y表示如果其中一個爲真,則該語句爲真。一個字符串總是如此,只要它不是空的(嘗試bool("no")看到)。這就是爲什麼你總是輸入questions=="Yes" or "yes"的部分。

你也可以把它變成其他東西更適合於這種情況下,如:

from distutils.util import strtobool 
if strtobool(questions): 
    # True, Yes, Y, 1 
else: 
    # False, No, N, 0 
+0

@dawg給出了每一個可能的答案:P thx的錯字修正:-) – Bharel