因此,我的一项任务是创建一个麻烦的程序,该程序将在查询中对关键字进行处理,并根据用户的输入将用户链接到解决方案。尽管此代码有效,但任何关键字都会始终需要第一个解决方案...有关如何纠正此问题的任何想法?非常感谢!
#CODE BEGINS
#damaged screen#
sol1 = ("If the battery of your mobile phone battery has swollen or changed appearance, we recommend removing the battery from the phone immediately and bringing them in store. This is something our technicians will have to look at.")
sol2 = ("We recommend bringing the phone in to a nearby store in able to gain help from a specialist.")
sol3 = ("We recommend factory resetting the phone or updating the mobile to the latest interface as the majority or errors are caused due to out-of-date interfaces.")
#subjected to damage#
sol4 = ("If the screen has been cracked, we recommend replacing the screen. If not, bring the phone into a store in order to seek help from a technician.")
sol5 = ("If the phone is water logged, we recommend removing the battery and allowing each piece of the phone to dry separately. Alternatively take the phone into a store.")
sol6 = ("We recommend taking the phone into a store, in order to seek help from a specialist.")
#editing#
sol7 = ("If you have recently changed the security settings on your phone there may be a corruption within your files. Please ensure you are entering your password correctly, and if this does not work, we recommend taking the phone into a store, in order to seek help from a specialist.")
sol8 = ("If you have recently deleted or edited files there may be a corruption within the files. In which case, please drop in to a nearby specialist in order to seek professional help.")
sol9 = ("If there has been a new update release for your device and many people are suffering a similar issue, there may be a manufacturing problem. We recommend taking the phone into a store, in order to seek help from a specialist.")
#file corruption#
sol10 = ("If you have recently attempted a factory reset and there has been an error you may need to retry this process. If the results come back the same, we recommend bringing the phone in to a nearby store in able to gain help from a specialist.")
sol11 = ("If there is a corruption within your files you may need to take your phone into a nearby store to gain professional help. This will ensure none of your files get lost in the process of storing them.")
sol12 =("We recommend factory resetting the phone or updating the mobile to the latest interface as the majority or errors are caused due to out-of-date interfaces.")
#corruptions due to download#
sol13 =("If you have recently download files from an external site there may be corruptions within the files or viruses. Please take your phone into a nearby store to gain professional help. This will ensure that no more damage is done to your device.")
sol14 =("If you have recently downloaded something from the app store your storage may be too full for your phone to run. In which case, please clear some space on your device.")
#If not solution can be provided, this outcome is the last message#
sol15 = ("Unfortunately we were not able to identify your problem. If you feel as though you may have made a mistake, you can restart this test. If there is no available solution we would recommend taking the phone into a store, in order to seek help from a specialist.")
import time
boolean = 0 #I have decided to use boolean operators in a way that they will act as subfunctions. This will help in directing the user to a specific solution instead of a general one.#
problemsolved = False
while problemsolved == False:
print("Hello, this system consists of multiple queries that will aim to help solve any problems that have arisen with your mobile device. If no solution is available the case number will be stored and revisited as soon as possible by a member of our customer support team.")
print("Let's get started, shall we?")
while boolean == 0:
problem1 = input("Is there something visably wrong with the phone?")
if problem1 == "yes":
print("Please describe in more detail.")
boolean += 1
elif problem1 == "no":
print("The problem is not to do with visable damage")
boolean+= 2
while boolean == 1:
problemexplainedone = str(input("Please decribe what is wrong with your phone."))
if ("battery" or "swollen" in problemexplainedone):
print(sol1)
elif ("screen" or "display" in problemexplainedone):
print(sol2)
elif ("error" or "message" in problemexplainedone):
print(sol3)
programfinished = input("Has the source of the problem been found and a solution suggested?")
if programfinished == "yes":
system = False
time.sleep(3)
exit()
elif programfinished == "no":
boolean += 1
while boolean == 2:
problem2 = input("Has the phone been subjected to damage?")
if problem2 == "yes":
print("Please describe in more detail.")
boolean += 1
elif problem1 == "no":
print("The problem is not to do with trauma to the hardware")
boolean+= 2
while boolean == 3:
problemexplainedtwo = str(input("Please decribe what is wrong with your phone."))
if ("battery" or "swollen" in problemexplainedtwo):
print(sol4)
elif ("screen" or "display" in problemexplainedtwo):
print(sol5)
elif ("error" or "message" in problemexplainedtwo):
print(sol6)
programfinished = input("Has the source of the problem been found and a solution suggested?")
if programfinished == "yes":
system = False
time.sleep(3)
exit()
elif programfinished == "no":
boolean += 1
答案 0 :(得分:1)
你必须改变像
这样的出现 if ("battery" or "swollen" in problemexplainedone):
print(sol1)
到
if ("battery" in problemexplainedone or
"swollen" in problemexplainedone"):
否则它总是返回True,选择第一个解决方案。
其他if(...... in ...)结构也是如此。
还有一些不相关的提示: