ComenzarEmpieza gratis

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

Ver curso

Instrucciones del ejercicio

  • Usa el método .format() de la cadena user_template para incluir el message del 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 como response.
  • Registra la response del bot usando el método .format() de la cadena bot_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("____")
Editar y ejecutar código