我目前正在做我的第一个 python 项目,构建一个聊天机器人,它可以从提出的问题中学习和训练自己。我该怎么做呢?
这是我一直在使用的示例代码。
import random
greetings = ['helo','heyhey','yooyoo', 'hello', 'hi', 'Hi', 'hey!','hey']
random_greeting = random.choice(greetings)
question = ['How are you?','How are you doing?','you good?','hows it going','you alright','you okay']
responses = ['Okay you?', "I'm fine wbu", 'not good rough day...', 'good what about you', 'tired :(, yourself?']
random_response = random.choice(responses)
while True:
userInput = input(">>> ")
if userInput in greetings:
print(random_greeting)
elif userInput in question:
print(random_response)
else:
print("I did not understand what you said")