S
S
SvetlanaOmsk2020-06-09 16:58:55
Python
SvetlanaOmsk, 2020-06-09 16:58:55

I can't figure out why the Yandex.Workshop program doesn't skip the task?

CHALLENGE

A lot of requests come in to servers, either from different users or from other servers. Change the process_query() function (the request handler) to support multiple different queries instead of just one.
Add a query argument to the process_query() function. This argument will tell you which request to process.
At the top of the process_query() function, add a check for the value of the query variable:
if the value is 'How many friends do I have?' - print the answer to this question, as in the previous task;
otherwise print '<unknown query>';
Anfisa should say hello at any request.
Add a process_query('How many friends do I have?') call to the main body of the program.
Add another process_query('What's my name?') call to the main body of the program.

MY DECISION!

spoiler
FRIENDS = ['Серёга', 'Соня', 'Дима', 'Алина', 'Егор']
def process_query(query):
# перенесите в функцию process_query() вот этот код:
    print('Привет, я Анфиса!')
    count = len(FRIENDS)
    if query=="Сколько у меня друзей?":
        print("У тебя "+ str(count) + " друзей")
    else:
        print("<неизвестный запрос>")
def print_friends_count(friends_count):
    if friends_count == 1:
        print('У тебя 1 друг')
    elif 2 <= friends_count <= 4:
        print('У тебя ' + str(friends_count) + ' друга')
    elif friends_count >= 5:
        print('У тебя ' + str(friends_count) + ' друзей')
process_query("Сколько у меня друзей?")
process_query("Как меня зовут?")

PROBLEM!
CODE DISPLAYS:
Hi, I'm Anfisa!
You have 5 friends
Hi, I'm Anfisa!
<unknown query>
BUT DOES NOT SKIP THE SOLUTION!
ANFISA SHOULD ALWAYS SAY A GREETING AT THE BEGINNING OF EVERY ANSWER!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question