Python如果输入句子相似的语句

Python if input statements with similar sentences

我目前正在尝试获得一个语音助手,我需要测试一个句子中的变量,例如

"What will the weather be in 'cityname'"

。我想出的基本事情是:

if 'What' in Sinput and ... sinput是输入词的列表,欢迎有更好的方法。

但唯一的问题是,当我执行第二个 if 语句时

"What will the weather be in 'cityname' tomorrow"

,两个语句都是 运行,我还没有找到解决方法!

这仅仅是因为两个 if 语句不能一起工作。您需要执行第一个 if 语句,然后执行 elif 语句,次数与您有命令的次数一样多。