A friend of Kenneth's invited him to a party but forgot to give him the address. Luckily, Kenneth is very organized and has two dictionaries, one that contains names and phone numbers; and another one that contains phone numbers and addresses. However, Kenneth needs your help to make it easier to find an address from a name. To achieve this, you will create a function called phone2address that takes three parameters:

⢠the first one is a dictionary that has names as keys and phone numbers as values
⢠the second one is a dictionary that has phone numbers as keys and addresses as values;
⢠the third one is a string with a friend's name.

To complete this function, you need to:

⢠First, use the phonebook and friend's name to find the desired phone number) .
Second, use the phone number and address book to find the correct address;
⢠Finally, you should return the address.

Respuesta :

Answer:

Explanation:

The following code is written in Python and creates the function as requested in the question...

def phone2address(phonebook, addressBook, friendName):

   phoneNumber = phonebook.get(friendName)

   address = addressBook.get(phoneNumber)

   return address

The function uses the dictionary (phonebook) to look for the friendName input as the key and then saves the phone number attached to that name in a variable called phoneNumber. Then we use that variable to search the addressBook dictionary to find the associated address and save it to the address variable. Finally, we return that address.