Skip to content
Advertisement

Advance on getting information from a menu

This is my entire code: https://github.com/samy-b/Assignment1/blob/main/addressbook

The main bit I am struggerling with is line 45. We have to create a function that will ask the user to enter the first letter of the surname of a person. Once the user has entered the letter then the program will display all of the attributes such firstname, lastname, address and phone number related to that letter. What can I use to make that happen?

Advertisement

Answer

Right after the user input the letter, make the program iterate through the keys of the info dictionary, using the subscription of [1] to get the Surname element of each list, and the subscription of [0] to get the first character of each surname:

      elif user_input == 3:
         firstletter = input("Please enter the first letter of their Surname")
         for line in info:
             if info[line][1][0] == firstletter:
                 print(info[line])
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement