Hello overflow的社区,今天我试图创建一个聊天机器人的项目,只是为了了解更多有关python的信息,但是当我创建一个循环并且没有#时,我遇到了一个问题。 39;知道如何解决它,并尝试搜索网站和本网站,但我没有找到任何东西,这是我的代码:
l_greeting = ["hello", "Hello", "HELLO", "hELLO", "مرحبا"]
print ("Welcome to sami's chatting bot")
greeting = str(input("Feel free to chat the bot: "))
if greeting in l_greeting:
print("Hello :D ")
else:
print ("I can't understand what you are saying, try again without
using caps")
break
而我真正想要的是让代码从单词不在我的单词列表中的位置运行,并使脚本继续在该单词之后留下的位置。
答案 0 :(得分:1)
input
放入while循环中,以便用户再次输入
再一次。检查以下更新的代码:
l_greeting = ["hello", "Hello", "HELLO", "hELLO", "مرحبا"]
print ("Welcome to sami's chatting bot")
while True:
greeting = str(input("Feel free to chat the bot: "))
if greeting in l_greeting:
print("Hello :D ")
else:
print ("I can't understand what you are saying, try again without using caps")