Member Avatar for deepakgupta2186

Given below is my telephone directory program.i made two lists one for name and the other for number.I merged it into a dictionary.performing basic functions..The problem is howto update the dictionary every time and how to save this program in a new directory,so as to call it any time and make the changes or view it..
please help me out..do make it complicated as i am a beginner..

Thanks a lot in advance

print "*****TELEPHONE DIRECTORY***" list1=[] list2=[] dict1={} temp=100 n=input("Enter the number of contacts : ") for i in range(0,n): name1=raw_input("Enter your name: ") num=input("Enter your phone number: ") list1.extend([name1]) list2.extend([num]) dict1=dict(zip(list1,list2))#to convert two list into dictionary print dict1 print """ 1:Add a contact 2:Search a contact 3:Delete a contact 4:Update a contact 5:View directory 6:Exit""" choice=input("Enter your choice") def add(dict1): name3=raw_input("Enter the new name you want to add: ") num3=input("Enter the number: ") dict1[name3]=num3 print dict1 def search(dict1,n,list1,temp): name2=raw_input("Enter the name whose number is to be found: ") for i in range(0,n): if list1[i]==name2: temp=i if temp!=100: print "Number is : ",list2[temp] def delete(dict1): name4=raw_input("Enter the name you want to delete: ") del dict1[name4] print dict1 def update(dict1,n,list1): name5=raw_input("Enter the name which you want to update: ") for i in range(0,n): if list1[i]==name5: temp=i if temp!=100: num5=input("Enter the new number") dict1[name5]=num5 print dict1 def view(dict1): print dict1 if (choice==1): add(dict1) elif (choice==2): search(dict1,n,list1,temp) elif (choice==3): delete(dict1) elif (choice==4): update(dict1,n,list1) else: view(dict1) 
Mansour_4 commented: Use file I/o sequential file+0
Member Avatar for TrustyTony

Hint: CODE button must be pushed before pasting code!

Member Avatar for woooee

You search a dictionary in this way, and note that names would be case sensitive:

def search(dict1): name2=raw_input("Enter the name whose number is to be found: ") if name2 in dict1: print name2, dict1[name]
Member Avatar for Mansour_4

To save the name and phone use i/O FILE
EX,

Fi= open ("filename.text")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.