所以,基本上,这是我的代码:
import random
import os
answer = input('What is the problem with your mobile phone? Please do not enter more than one sentence.')
print('The program has detected that you have entered a query regarding: '
if 'wet' or 'water' or 'liquid' or 'mobile' in answer:
print('Put your mobile phone inside of a fridge, it sounds stupid but it should work!')
我想知道的是,例如,如果用户输入关键字“wet”和“mobile”作为输入,我如何反馈给他们知道我的程序已识别他们的查询。
因此,通过说“程序检测到您输入了有关以下内容的查询:”,我如何将他们的关键字过滤到这句话中,比如说,如果他们输入“我的手机最近被弄湿了”,我想选择“移动”和“湿”而不说:
print('The program has detected that you have entered wet')
因为在我看来这听起来很愚蠢。
谢谢
最佳答案
如果我正确理解你的问题,这应该可以解决你的问题。只需将 print 语句放在 if 条件中即可!我想很简单:)
import random
import os
answer = input('What is the problem with your mobile phone? Please do not enter more than one sentence.')
if 'wet' or 'water' or 'liquid' or 'mobile' in answer:
print('The program has detected that you have entered a query regarding: water') # or anything else wet or whatever
print('Put your mobile phone inside of a fridge, it sounds stupid but it should work!')
关于Python 检查用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33833640/