EchoBot II
Después de escribir tu función respond(), ahora vas a definir una función llamada send_message() con un único parámetro message que registre el message y la respuesta del bot.
Este ejercicio forma parte del curso
Creación de chatbots en Python
Instrucciones del ejercicio
- Usa el método
.format()de la cadenauser_templatepara incluir elmessagedel usuario en la plantilla de usuario y muestra el resultado con print. - Llama a la función
respond()con el mensaje pasado y guarda el resultado comoresponse. - Registra la
responsedel bot usando el método.format()de la cadenabot_template. - Envía el mensaje
"hello"al bot.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# 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("____")