Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't excute my code
#5
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:

sam=99912222
Not found
harry=12299933
and the input format should be this:
3
sam 99912222
tom 11122222
harry 12299933
sam
edward
harry
This 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
Thanks and regards,
RavCoder
Reply


Messages In This Thread
Don't excute my code - by RavCOder - Sep-30-2019, 10:31 AM
RE: Don't excute my code - by buran - Sep-30-2019, 10:38 AM
RE: Don't excute my code - by RavCOder - Sep-30-2019, 12:49 PM
RE: Don't excute my code - by jefsummers - Sep-30-2019, 02:13 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 12:34 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 12:48 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 01:21 PM
RE: Don't excute my code - by jefsummers - Oct-01-2019, 01:48 PM
RE: Don't excute my code - by buran - Oct-01-2019, 02:10 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 02:34 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 02:40 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 03:45 PM
RE: Don't excute my code - by ichabod801 - Oct-01-2019, 03:51 PM
RE: Don't excute my code - by RavCOder - Oct-01-2019, 03:56 PM
RE: Don't excute my code - by jefsummers - Oct-01-2019, 04:22 PM
RE: Don't excute my code - by RavCOder - Oct-02-2019, 10:21 AM
Problem with dictionary - by RavCOder - Oct-01-2019, 07:58 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020