Q. Write code to create a python dictionary. add two entries to the dictionary: associate the key ‘name’ with the value ‘jivin’, and associate the key ‘phone’ with “0000-0000”
Add two more name and their phones in the dictionary after getting input from user. then ask the user a name and print its corresponding phone.
Answer =
dic = {} num = int (input ("How many names do you want to enter :- ")) for i in range (num) : name = str(input ("Enter the name :- ")) phone = int(input ("Enter the Phone :- ")) dic[name] = phone data = str(input ("Enter name to get corresponding phone number :- ")) print (dic.get(data, "No such name's found."))
Output :-
How many names do you want to enter :- 4
Enter the name :- Path
Enter the Phone :- 123456789
Enter the name :- Walla
Enter the Phone :- 569874123
Enter the name :- Python
Enter the Phone :- 456532312
Enter the name :- Express
Enter the Phone :- 000111223
Enter name to get corresponding phone number :- Walla
569874123
>>>
Enter the name :- Path
Enter the Phone :- 123456789
Enter the name :- Walla
Enter the Phone :- 569874123
Enter the name :- Python
Enter the Phone :- 456532312
Enter the name :- Express
Enter the Phone :- 000111223
Enter name to get corresponding phone number :- Walla
569874123
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )