Oct-01-2019, 07:58 AM
Hi,
I tried this solution for this challenge: Given n names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each name queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for name is not found, print Not found instead.
The result should be this:
Thanks and regards,
RavCoder
I tried this solution for this challenge: Given n names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each name queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for name is not found, print Not found instead.
The result should be this:
sam=99912222 Not found harry=12299933and the input format should be this:
3 sam 99912222 tom 11122222 harry 12299933 sam edward harryThis is my code that I developed:
def list_address_book(): n = int(input()) address_book = dict() user_input = input() key , value = user_input.split() address_book [key] = value for key , value in address_book : if key == "": print("Not found") else: print (address_book[key] [value]) if __name__ == "__main__": list_address_book()
Error:Traceback (most recent call last):
File "Solution.py", line 19, in <module>
list_address_book()
File "Solution.py", line 10, in list_address_book
for key , value in address_book :
ValueError: too many values to unpack (expected 2)
I don't know if I put global variables or I was wrong some condition. ![Huh Huh](https://python-forum.io/images/smilies/huh.png)
Thanks and regards,
RavCoder