InterviewSolution
Saved Bookmarks
| 1. |
Write a Python program to input ‘n’ names and phone numbers to store it in a dictionary and to input any name and to print the phone number of the particular name. |
|
Answer» phonebook = dict( ) n = input (“Enter total number of friends”) i = 1 while i<=n : a = raw_input (“Enter name”) b = raw_input (“Enter phone number”) phonebook [a] = b i = i + 1 name = raw_input (“Enter name”) f = 0 l = phonebook.keys( ) for i in l : if (comp (i, name) = = 0) : print “Phone number =”, phonebook[i] f = 1 if (f = = 0): print “Given name not exist” |
|