Answer the question
In order to leave comments, you need to log in
Can't figure out why the code doesn't work?
Condition of the problem: I work as a secretary and I constantly receive various documents. I have to be very careful not to lose a single document. The document catalog is stored in the following form: The list of shelves on which the documents are stored is stored in the following form: It is necessary to implement custom commands that will perform the following functions: p - people - a command that will ask for the document number and display the name of the person to whom it belongs
documents = [
{"type": "passport", "number": "2207 876234", "name": "Василий Гупкин"},
{"type": "invoice", "number": "11-2", "name": "Геннадий Покемонов"},
{"type": "insurance", "number": "10006", "name": "Аристарх Павлов"}
]
directories = {
'1': ['2207 876234', '11-2'],
'2': ['10006'],
'3': []
}
def documents_number(people):
user_input = input('Введите номер документа')
for documents in people:
if documents_number == (documents['number']):
print(documents['name'])
print(documents['name'])
return user_input
print(documents_number(documents))
Answer the question
In order to leave comments, you need to log in
You always output the last document, because the documents that looped over left the value of the last repetition and user_input is not used in any way. The correct one is much easier.
def documents_number(people):
user_input = int(input('Введите номер документа'))-1
return people[user_input]["name"]
print(documents_number(documents))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question