Začněte nyníZačněte zdarma

EchoBot II

Teď, když máš napsanou funkci respond(), definuj funkci send_message() s jedním parametrem message, která zaloguje zprávu message a odpověď bota.

Toto cvičení je součástí kurzu

Building Chatbots in Python

Zobrazit kurz

Pokyny k cvičení

  • Pomocí metody .format() řetězce user_template vlož uživatelskou zprávu message do šablony a výsledek vypiš.
  • Zavolej funkci respond() s předanou zprávou a výsledek ulož jako response.
  • Zaloguj botovu odpověď response pomocí metody .format() řetězce bot_template.
  • Pošli botovi zprávu "hello".

Interaktivní cvičení na vyzkoušení si v praxi

Vyzkoušejte si toto cvičení dokončením tohoto ukázkového kódu.

# 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("____")
Upravit a spustit kód