Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using a dictionary of dictionaries for my main method, I need help to fix my def view_menu, def add_menu, def del_menu. to use

image text in transcribed

image text in transcribed

I am using a dictionary of dictionaries for my main method, I need help to fix my def view_menu, def add_menu, def del_menu. to use my dictionary.

image text in transcribed

thanks, it's python code.

*Yakob_logerfo_contact Manager.py - /Users/yakoblogerfo/Down 15 def menu(): # printing the menu 16 print("COMMAND MENU") 17 print("list Desplay all contacts") 18 print("view - a contact") 19 print("add add a contact") 20 print("field - view field for all") 21 print("del - Delete a contact") 22 print("exit - Exit program") 23 24 def list_menu(contacts): # listing contacts & fuction 25 i = 1 26 for name in sorted (contacts.keys (): #length of contacts times (no.of contacts) 27 print(i, ". ", name, sep="") #prints contact names 28 i= i+1 29 30 def view_menu(contacts): # view menu fuction to view spesific contact 31 i=2 32 number=int(input("Number: ")) # taking the number of the contact as input 33 i= i-1 # contact index in list 34 print("Name: ", contacts[i][0]) # print the name 35 print("Email: contacts[i][1]) # print the Email 36 print("Phone: , contacts[i][2]) # print the phone number 37 38 def add_menu(contacts): # addint a new contact to the contact list 39 i=3 40 name=input("name: ") # takes inpute of name, email, phone 41 email=input("Email:") 42 phone=input("Phone: ") 43 add=[] 44 add.append(name) # appending input 45 add.append(email) 46 add.append(phone) 47 contacts.append(add) # appends list to the contact list 48 print(name, "was added") 49 50 def del_menu(contacts): # del_menu fuction to delet contact 51 i=4 52 number=int(input("Number: ")) # number of contact 53 name=contacts[number-1][0] # storing the name of the contact 54 del contacts [number-1] #delets a list of contact from the list based on index 55 print(name, "was deleted") 56 57 def main(): 58 print("contact manager") 59 contacts = { "Joel": 60 {"address" : "1500 Anystreet, San Francisco, 94110", "company":"A startup", "mobile": "555-555-1111"}, 61 62 "Anne": {"address" : "1000 Somestreet, Fresno, CA 93704", 63 "state" : "California", 64 "landline": "125-555-2222", "company": "Some Great Company"}, 65 66 "Sally": {"state" : "Illinois", "landline":"217-555-1222", "company": "Illinois Technologies", 67 "mobile": "217-333-2353"}, 68 "Ben": 69 {"address" : "1400 Another Street, Fresno CA 93704", 79 "state" : "California", "mobile": "125-555-4444"} 71 72 } 44 add.append(name) # appending input 45 add.append(email) 46 add.append(phone) 47 contacts.append(add) # appends list to the contact list 28 print (name, "was added") 49 50 def del_menu(contacts): # del_menu fuction to delet contact 51 i=4 52 number=int(input("Number: ")) # number of contact 53 name=contacts [number-1][0] # storing the name of the contact 54 del contacts [number-1] #delets a list of contact from the list based on index 55 print(name, "was deleted") 56 57 def main(): 58 print("contact manager") 59 contacts = { "Joel": 60 {"address": "1500 Anystreet, San Francisco, 94110","company":"A startup", 61 "mobile": "555-555-1111"}, 62 "Anne": 63 {"address": "1000 Somestreet, Fresno, CA 93704", 64 "state" : "California", 65 "landline": "125-555-2222", "company" : "Some Great Company"}, 66 "Sally": 67 {"state" : "Illinois", "landline":"217-555-1222", "company" : "Illinois Technologies", 68 "mobile": "217-333-2353"}, 69 "Ben": 70 {"address" : "1400 Another Street, Fresno CA 93704", 71 "state" : "California", "mobile": "125-555-4444"} 72 } 73 74 75 76 77 menu() # calling menu fuction 78 while True: #infinite loop 79 command=input(" command: ") # taking comand 88 if command=="list": #condition based on userinput 81 list_menu(contacts) 82 elif command=="view": 83 view_menu (contacts) 84 elif command=="add": 85 add_menu(contacts) 86 elif command=="del": 87 del_menu(contacts) 88 elif command=="exit": 89 break 90 91 print("Enter valid command") 92 print("bye") 93 if __name__=="__main__": 94 main() # calling main fuction 95 96 97 98 99 else: *Yakob_logerfo_contactManager.py - /Use 1 #Assignment: contactManager.py 2 #class: Prog 120 3 #Date: 1/17/2021 4 #Author: Yakob Logerfo 5 #Description: Program to manage a list of contacts 6 7 # Program to help user manage contacts information 8 # Supports 9 # listing all contacts, 0 # viewing/adding/deleting a contact 1 # printing a given field for all contacts. 2 # Program uses dictionary of dictionaries to hold the contacts information.def main(): 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions