0
如何使if
语句具有两个值,即同义词即“display”和“screen”,然后是and
和另一个字符串,如“broken”。这个想法是,只有在出现“显示”,“破碎”或“屏幕”和“破碎”时才会输出。不知道如何在if语句中编写或和语句
我曾尝试:
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")
这是最紧凑的方式吗? –
可能是的,尽管代码最小化是一个非常困难的问题。 –
你也可以做任何(x [in [“display”,“screen”]中的x),这个例子比较长,但是你可以在其他位置创建列表和/或添加更多的东西所以更具可扩展性 – Copperfield