我的程序首先询问用户他们的手机出了什么问题,当用户写下答案时,程序检测关键字并输出解决方案。我用了“或”语句,但当我输入“我的手机掉进水里,我的扬声器坏了”时,它应该会输出“你需要新的扬声器。如果waters与您联系过,您可能还需要一个新的主板,如果它没有启动,但它会输出“您需要更换屏幕”
有谁能告诉我我做错了什么,告诉我今后如何克服这个问题。你知道吗
import time #This adds delays between questions
name = input ("what is your name?")
problem1 = input("hello there,what is wrong with your device?")
if "cracked" or "screen broke" in problem1:
print("you will need your screen replacing")
elif "water" or "speakers" in problem:
print("you need new speakers. if waters been in contact you also may need a new motherboard if it doesnt come on")
我想你弄错了。在编程中,
or
与英语略有不同。x or y in z
表示"is x True or is y in z?"
。如果第一个参数(x
)是非空的,这意味着它的计算结果是True
。不检查z
中是否存在任何东西。如果x
为空,则计算结果为False
,并检查y
在z
中的存在,但不检查x
的存在。您需要为每个测试创建一个新的测试。另外,您在第二个elif
中使用了problem
而不是problem1
:相关问题 更多 >
编程相关推荐