0
Good night,
I have a Python exercise that has stopped me, it is the following:
Read and store in a dictionary the name, age and phone number of your contacts, the key being the name. When typing an empty string for the name, the program stops reading and ends. Display on the screen the data read in alphabetical order by the name of the contacts. A possible solution to sort alphabetically is to use the Sort method. Then store the contacts in two other dictionaries, using the age criterion: under 18 years in one and the largest in another dictionary, eliminating the original. Display on screen the two dictionaries resulting from the separation.
I was able to generate the dictionary and its lists according to the entry and break of the program if the first entry of the name is string vázia.
However, I cannot print the dictionary alphabetically, since if I apply Sort to the name key, it only adjusts it and I apply all the information to the other ones. Also I could not think of a way to make this separation of dictionaries, dividing the contacts that are older than 18 years in one and the minors in another dictionary and eliminating the original.
Could someone give me an idea please?
Code to date:
informations = {'name':[], 'age':[], 'cellphone':[]}
for i in range(3):
name = str(input('Qual o nome do seu contato? '))
if name == "":
print('Programa encerrado...')
break
age = int(input('Qual a idade do seu contato? '))
cellphone = int(input('Qual o número de celular do seu contato? '))
informations['name'].append(name)
informations['name'].sort()
informations['age'].append(age)
informations['cellphone'].append(cellphone)
print('')
print(informations)
Our show Giovanni, now cleared me very much on this issue, thank you very much for the help
– Marcos Prado