如何使 if
语句具有两个同义词,即"display"和"screen",然后是 and
和另一个字符串,如"broken" . 我们的想法是只有在有"display"和"broken"或"screen"和"broken"时才会输出 .
我试过的:
def issuesection():
issue = input("Type in your issue in a sentence and we will try out best to help you with a solution: ")
if "display" or "screen" in issue and "broken" in issue:
print('WORKED')
else:
print("FAIL")
1 回答
问题是Python看到:
如:
所以它评估了
"display"
和 every non-empty string is considered to be True 的真实性 .所以你应该把它重写为:
此外,由于您希望
and
绑定到两个in
检查,您还应该括号作为and
的左操作数:现在它说:“如果显示或屏幕出现问题,则条件成立; and 破坏也存在问题". Without the brackets it would state: "如果显示有问题,条件成立; or 屏幕和破损问题” .