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
Pokyny k cvičení
- Pomocí metody
.format()řetězceuser_templatevlož uživatelskou zprávumessagedo šablony a výsledek vypiš. - Zavolej funkci
respond()s předanou zprávou a výsledek ulož jakoresponse. - Zaloguj botovu odpověď
responsepomocí metody.format()řetězcebot_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("____")