Create a program addressbookpy that manages an individuals a

Create a program (addressbook.py) that manages an individual\'s address book. The program should allow a user to add new contacts, display the entire address book, search for a contact and display that contact\'s information, modify the information for a specific contact, delete a contact, and exit the program. These features should work as follows: Display a menu of the options. Use a function for this. Get a menu option from the user. Remember to perform input validation Add New Contact: Get the name, address, phone number, and email address from the user. As the user adds new contacts, add the contact data to a list and also append it a file contacts. text. Make sure to write out the data such that each piece of information about an individual is on a separate line. For example, \"Mickey\" and \"12 Disney Street\" should be on separate lines. Display Address Book: Display all the contents of the address book. Search for a contact Ask the user for the name of the contact they are searching for then search for that individual in the list and if they are found in the list, display all the contact information for that individual. If the person is not found, display a message the user saying \"There is no contact with that name in your address book.\" Modify Contact: Ask the user for the name of the contact whose information needs be modified. Find the information for that individual in your list and display it Now ask the user which aspect of that individual\'s information would they like to modify: name, address, phone number, or email address. Accordingly, get input from the use and modify that information in your list. Then delete the old contacts. txt file are rewrite all the contact information to a \'new\' file called contacts. txt. Delete Contact: Ask the user for the name of the contact to delete. Find that individual\'s contact information in the list and delete it from the list Then delete the old contacts. txt file and rewrite the entire list to a \'new\' file called contacts. txt.

Solution

contacts = {}
def display_menu():
\"Displays the menu options\"
print \"############ MENU ##############\"
print \"1.Add New Contact\"
print \"2.Display Address book\"
print \"3.Search For Contact\"
print \"4.Modify Contact\"
print \"5.Delete Contact\"
print \"6.Exit\"
def search_contact(name):
\"Searches for a given name and return 0 if not found\"
for i in contacts:
if(contacts[i][0] == name):
return i
return 0

def delete_contact():
\"deletes a given contact name\"
name = raw_input(\"Enter name:\");
ind = search_contact(name)
if(ind):
del contacts
print \"Contact Delete successfully\"
else:
print \"Contact Information not found\"
write_to_file()
def modify_contact():
\"modifies a given contact name\"
name = raw_input(\"Enter name:\");
ind = search_contact(name)
if(ind):
print \"Update\ 1.Name\ 2.Address\ 3.Phone\ 4.Email\"
choice = int(input())
if(choice==1):
update = raw_input(\"Name:\")
contacts[ind][0] = update
elif(choice==2):
update = raw_input(\"Address:\")
contacts[ind][1] = update
elif(choice==3):
update = raw_input(\"Phone:\")
contacts[ind][2] = update
elif(choice==4):
update = raw_input(\"Email:\")
contacts[ind][3] = update
else:
print \"Invalid Choice\ \"
else:
print \"Contact Information Not found\"
write_to_file()
def add_new_contact():
\"Adds a new contact to the contact_book\"
name = raw_input(\"Name:\")
address = raw_input(\"Address:\")
phone = raw_input(\"Phone:\")
email = raw_input(\"Email:\");
contacts[len(contacts)+1] = [name,address,phone,email]
write_to_file()
def write_to_file():
\"writes the contact details to a file\"
file = open(\"contact.txt\",\"w\")
for i in contacts:
file.write(\"\ \".join(contacts[i]))
file.write(\"\ \");
file.close();
def read_to_dict():
\"Reads all the contact details to a dict\"
file = open(\"contact.txt\",\"r\")
text = file.read()
textl = text.split(\"\ \")
print textl
factor = 0
contact = []
for i in textl:
if(factor==4):
contacts[len(contacts)+1] = contact
contact = []
contact.append(i)
factor=1
else:
contact.append(i)
factor += 1
file.close()
def display_address_book():
\"Displays all the contact details\"
print \"--------------Address Book-----------------\"
for i in contacts:
display_contact(contacts[i])
print \"----------------------\"

def display_contact(l):
\"Displays a given contact\"
print \"Name : \",l[0]
print \"Address : \",l[1]
print \"Phone : \",l[2]
print \"Email : \",l[3]

read_to_dict() # read all the contats from contact.txt file
while True:
display_menu()
option = int(input())
if(option==1):
add_new_contact()
elif(option==2):
display_address_book()
elif(option==3):
na = raw_input(\"Enter name:\")
ind = search_contact(na)
if(ind):
display_contact(contacts[ind])
else:
print \"Contact Information not found\"
elif(option==4):
modify_contact()
elif(option==5):
delete_contact()
elif(option==6):
break;
else:
print \"Invalid Option\"

 Create a program (addressbook.py) that manages an individual\'s address book. The program should allow a user to add new contacts, display the entire address b
 Create a program (addressbook.py) that manages an individual\'s address book. The program should allow a user to add new contacts, display the entire address b
 Create a program (addressbook.py) that manages an individual\'s address book. The program should allow a user to add new contacts, display the entire address b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site