-3
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 closes.
Display the read data alphabetically by contact name on the screen. 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.
Print on the screen a test of your program using as a first registration your name, as telephone your UK, and as age the last two digits of your UK.
If anyone can help me, I’m totally lost in what to do from the first step. I’ve even solved the bold part of the code below. I’m not knowing how to do the bottom, I’ve researched everything that is side, always generates error after error.
lista = []
while True:
sair = input('Deseja cadastrar um contato ? [S/N]:')
if sair == ' ':
break
nome = input('Qual o nome do contato?:')
idade = int(input('Qual a idade?:'))
tel= int(input('Qual o telefone do contato:?'))
lista.append([nome,idade,tel])
print(lista)
listaordenada = sorted(lista)
for item in listaordenada:
print('Nome:{} Idade :{} Telefone:{}'.format(item[0], item[1], item[2]))
The exercise asks you to store the data in a dictionary in your program is using a list.
– Augusto Vasques