Get startedGet started for free

EchoBot II

Having written your respond() function, you'll now define a function called send_message() with a single parameter message which logs the message and the bot's response.

This exercise is part of the course

Building Chatbots in Python

View Course

Exercise instructions

  • Use the user_template string's .format() method to include the user's message into the user template, and print the result.
  • Call the respond() function with the message passed in and save the result as response.
  • Log the bot's response using the bot_template string's .format() method.
  • Send the message "hello" to the bot.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create templates
bot_template = "BOT : {0}"
user_template = "USER : {0}"

# Define a function that sends a message to the bot: send_message
def ____(____):
    # Print user_template including the user_message
    print(____.format(____))
    # Get the bot's response to the message
    response = ____(____)
    # Print the bot template including the bot's response.
    print(____.format(____))

# Send a message to the bot
send_message("____")
Edit and Run Code