我正在尝试创建一个聊天机器人,可以与人类进行简单的对话。聊天机器人需要一个子类BoredChatbot
,该子类将聊天机器人作为超类继承,但如果用户的输入长度超过20个字符,则会生成以下消息:
“zzz... Oh excuse me, I dozed off reading your essay.”
到目前为止,我已经:
^{pr2}$这不起作用-它打印:
"It is very interesting that you say: + human_message"
不管长度。在
我还试图切换if语句的顺序,使其出现在方法之外。在
class BoredChatbot(Chatbot):
def bored(self):
""" Returns the Chatbot's response to length > 20 characters"""
return "zzz... Oh excuse me, I dozed off reading your essay."
sally = BoredChatbot("Sally")
human_message = input(sally.greeting())
if len(human_message) > 20:
print(sally.bored(human_message))
else:
print(sally.response(human_message))
但这给了我一个错误信息:
AttributeError: 'Chatbot' object has no attribute 'bored' on line 31
为什么它在BoredChatbot
内的方法注册时不觉得无聊?谢谢你帮我把这件事弄清楚-我觉得很接近了。在
那么,让我们看看这里。在
什么是
prompt_from_human
?你怎么从bored(self)
得到这个?另外,return(response)
将抛出一些错误,因为1)self.response()
是实际函数,但是2)response
也没有定义。在所以,解决这些问题,我认为您根本不需要
^{pr2}$bored
函数。您应该重写response
函数并返回超级函数,以保持对象函数的一致性。在当然是
sally = BoredChatBot("Sally")
相关问题 更多 >
编程相关推荐