我是新来的python,我试图开发一个手机故障诊断程序,我问用户他们的设备有什么问题,如果我的程序检测到“湿”或“水” '它会回复一个结果。另一个例子是'屏幕被破解'。我遇到问题,如果我输入'我的屏幕被破解'。我的代码没有检测到它。任何帮助感谢!Python - 字符串中的字会影响结果
的片段我的代码:
print(60 * '-')
print('Could you describe what is wrong with your device?')
print(60 * '-')
time.sleep(1)
user_problem = input('')
if user_problem in ('water', 'waterdamage', 'rain', 'toilet', 'pool', 'sea', 'ocean', 'river',):
print('WATERDAMAGE VARAIBLE')
elif user_problem in ('screen', 'cracked', 'shattered', 'smashed',):
print('SCREEN VARIABLE')
你试图匹配'我的屏幕cracked'到每个项目中的元组...尝试分裂输入和单独匹配的话。 – MooingRawr