Get startedGet started for free

EchoBot I

Hello, World!

You'll begin learning how to build chatbots in Python by writing two functions to build the simplest bot possible: EchoBot. EchoBot just responds by replying with the same message it receives.

In this exercise, you'll define a function that responds to a user's message. In the next exercise, you'll complete EchoBot by writing a function to send a message to the bot.

This exercise is part of the course

Building Chatbots in Python

View Course

Exercise instructions

  • Write a function called respond() with a single parameter message which returns the bot's response. To do this, concatenate the strings "I can hear you! You said: " and message.
  • Store the concatenated strings in bot_message, and return this result.

Hands-on interactive exercise

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

bot_template = "BOT : {0}"
user_template = "USER : {0}"

# Define a function that responds to a user's message: respond
def ____(____):
    # Concatenate the user's message to the end of a standard bot respone
    bot_message = "____" + ____
    # Return the result
    return ____

# Test function
print(respond("hello!"))
Edit and Run Code