1. 学习
  2. /
  3. 课程
  4. /
  5. Building Chatbots in Python

Connected

练习

Chitchat

Now you're going to leave the simple EchoBot behind and create a bot which can answer simple questions such as "What's your name?" and "What's today's weather?"

You'll use a dictionary with these questions as keys and the correct responses as values.

This means the bot will only respond correctly if the message matches exactly, which is a big limitation. In later exercises you will create much more robust solutions.

The send_message() function has already been defined for you, as well as the bot_template and user_template variables.

说明 1 / 共 2 个

undefined XP
    1
    2
  • Define a respond() function which takes in a message argument, checks if the message has a pre-defined response, and returns the response in the responses dictionary if there is a match, or the "default" message otherwise.