Andextraction why the bot doesn't see nested function?

The job:

The server receives many requests from different users or from other servers. Change the function process_query() (request handler) to support several different queries, not just one.
Add a query argument to the function process_query(). This argument will tell the query that you want to handle.
In the beginning of the function process_query() add a test variable value query:
if the value is 'How many friends do I have?' — print the answer to this question, as in the previous task;
otherwise, print '<unknown request>';
Anfisa should greet with any query.
Add a call to process_query('How many friends do I have?') in the main body of the program.
Add another call process_query('what's my name?') in the main body of the program.

Use the comparison if query == ... to define the query.

Initial code:
FRIENDS = ['Serge', 'Sonia', 'Dima', 'Alina', 'Egor']
friends_count = 0
def print_friends_count(friends_count):
 if friends_count == 1:
 print('you Have 1 friend')
 elif 2 <= friends_count <= 4:
 print('you Have' + str(friends_count) + 'friend')
 elif friends_count >= 5:
 print('you Have' + str(friends_count) + 'friends')

def process_query():
# move in the function process_query() here's the code:
 print("hi, I'm Naomi!")
 count = len(FRIENDS)

Naughty solution:
FRIENDS = ['Serge', 'Sonia', 'Dima', 'Alina', 'Egor']
count = len(FRIENDS)
def process_query(query):
 print('hi, I'm Naomi!')
 if query == 'How many friends do I have?':
 def print_friends_count(count):
 if count == 1:
 print('you Got',count,'friend')
 elif 2 <= count <= 4:
 print('you Got',count,'friend')
 elif count >= 5:
 print('you Got',count,'friends')
 print('<unknown request>')
process_query('How many friends do I have?')
process_query('what's my name?')

The result meets the issues of the task:

Hi, I'm Naomi!
You have 5 friends
Hi, I'm Naomi!
<unknown request>

However, the bot does not accept the answer, writes "the Function of print_friends_count() does not exist. Do not remove it."
Can't understand why :(

And another question:
Function print_friends_count(count) is executed by a team print_friends_count(count). If you can, please explain why the call to the function process_query(query) is unacceptable in this program. If you call it after the ELSE statement, team process_query(query), then the cyclical output, depending on the designated function call (the padding +/- 4 spaces on the next line after the ELSE):

Hi, I'm Naomi!
You have 5 friends
Hi, I'm Naomi!
You have 5 friends


Hi, I'm Naomi!
You have 5 friends
Hi, I'm Naomi!
unknown request
Hi, I'm Naomi!
unknown request
April 19th 20 at 12:06
2 answers
April 19th 20 at 12:08
A function in Python is an object of the first kind.
In Python all objects. Function and number, and string and a list and a dictionary and a class and an instance of the class.
Each object can have many names. Consider the object name as a label attached to the tea bag.
Here print_friends_count is the name of the variable and the parenthesis after it are forced to call the object available ol that name as a function. The challenge occurs with the transfer of a single argument, which is available by the name count.

If the code on the Python in some expression (a function call is an expression; the result of the call is always some value, such as None, Yes, None is also an object, it returns the default function) is found a name, this name is searched in the local scope of this function (i.e. the function itself), then in the scope where the function is declared, then even higher and so on up to the module. The top - global scope is the module. If the name is not found anywhere, even in a module, it will posesa among the __builtins__ is a dictionary with names and objects that are available everywhere. If is not there, and there will be an error.
In your case, the function should leave at the module level. Cause it can be anywhere inside the module, but on the condition that the operator function Declaration already made.

When you run the program (or import module) in turn executes all operators (imports, declarations of functions/classes naming to the results of some expressions...)

I think you should download a book about Lutz learning Python from scratch and thoughtful read. In order.
Thanks for the explanation, I decided, really spent almost 8 hours. It turns out we need to know where to make the call.
You mean mark Lutz “Programming Python”? Tried to read, but the book difficult for me: a lot of theory without practice, then I don't use simply forgotten :( - philip51 commented on April 19th 20 at 12:11
April 19th 20 at 12:10
I suggest you to refer not to the toaster, namely in Yandex Workshop, where I took an introductory course, support helps, even without the payment of a main course and I assure you that they will help you better than people on the toaster.
Thank you - philip51 commented on April 19th 20 at 12:13

Find more questions by tags Python