Question -
Answer -
phonebook=dict( )
n=input(” Enter total number of friends to create a telephone book”)
i=l
while i<=n:
a=raw_input(“enter name”)
b=raw_input(“enter phone number”)
phonebook[a]=b
i=i+l
name=raw_input(“enter friend’s name to search for”)
f=0
l=phonebook.keys( )
for i in l:
if(cmp(i,name) == 0):
print “Phone number= “,phonebook[i]
f=l
if (f==0):
print “Given name not exist”
Output:
Enter total number of friends to create a telephone
book 5
enter name Ramu
enter phone number 9842311111
enter name Raju
enter phone number 9842309564
enter name Sarita
enter phone number 9842398765
enter name Sowmya
enter phone number 9842399922
enter name Karan
enter phone number 9842366554
enter friend’s name to search for Sarita
Phone number = 9842398765