bot_template = “BOT : {0}” user_template = “USER : {0}”
# Define a function that sends a message to the bot: send_message
def send_message(message):
# Print user_template including the user_message
print(user_template.format(message))
# Get the bot's response to the message
response = respond(message)
# Print the bot template including the bot's response.
print(bot_template.format(response))
# Define variables
name = "Gowri"
weather = "cloudy"
age = "10"
# Define a dictionary with the predefined responses
responses = {
"what's your name?": "my name is {0}".format(name),
"what's today's weather?": "the weather is {0}".format(weather),
"what's your age?": "my age is {0}".format(age),
"default": "default message"
}
# Return the matching response if there is one, default otherwise
def respond(message):
# Check if the message is in the responses
if message in responses:
# Return the matching message
bot_message = responses[message]
else:
# Return the "default" message
bot_message = responses["default"]
return bot_message
send_message("what's your name?")