以下代码一直有效,直到我在此行下添加代码:
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)
答案 0 :(得分: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
表示如果一个为True,则该语句为真。只要字符串不为空,字符串始终为true(请尝试bool("no")
查看)。这就是您始终使用questions=="Yes" or "yes"
输入零件的原因。
您还可以将其更改为更适合此案例的其他内容,例如:
from distutils.util import strtobool
if strtobool(questions):
# True, Yes, Y, 1
else:
# False, No, N, 0