Phonebook

Asked

Viewed 215 times

-2

I’m developing a python program that should receive a contact’s name and phone number and store in a calendar in alphabetical order. So far so good. The problem appears when I need to implement a search option (line 19), where the user informs the name of the contact he is looking for and the program returns the requested name and number.

Below this program, someone can help me implement this function?

Phonebook

agenda=[]
n_contato=int(input("Quantos contatos voce deseja salvar? "))
itens=1
def Agenda_Telefonica
    for i in range(n_contato):
        contato=[]
        for j in range(itens):
            nombre=input("Cual es el nombre del contato, mi amigx? ")
            telefono=int(input("Cual es el telefono? "))
            contato.append(nombre)
            contato.append(telefono)
        agenda.append(contato)
        return agenda
agenda.sort()   ### colocado em ordem alfabetica ###
print("Vossa agenda telefonica tienes ",len(agenda),"contatos salvos, sendo ellos",agenda)

index=agenda.index.contato.index(input("Estas a procurar el contato de quem? "))
print("El contatito que tu procuras es: ",agenda(index))
  • Reformat your question and code better, use the markdown syntax to post snippets of code in your question, this way people will be more able to help you.

1 answer

0

The entire agenda could be a dictionary whose key is the person’s name and the value is the phone number (or a phone list if you prefer). It makes no sense to implement the agenda as a list that has another list within.

Since the agenda is now a dictionary, you can save a contact this way:

agenda[“fulanito”] = “666-2424”

And you can get your phone back that way:

print(agenda [“fulanito”])

The list of all the names in the agenda you would have with the Keys method, this way:

agenda.keys()

This way, the user type the contact name and you return the agenda item easily.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.