0

我目前正在做我的第一个 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") 
4

1 回答 1

3

一个简单的算法是,当它没有问题的数据库“答案”时,它可以将问题回显给用户,然后将用户的答案添加到数据库中。

于 2015-05-23T23:25:36.740 回答