Please check the picture and add one more function(def) to display menu and fix the error in the code. Write a program that keeps names and email addresses in a dictionary as key-value pairs. You Must create and use at least 5 meaningful functions. A function to display a menu A function to look up a person’s email address A function to add a new name and email address A function to change an email address A function to delete a name and email address.
Python 3
NO IMPORT PICKLE
Please check the picture and add one more function(def) to display menu and fix the error in the code.
Write a
- A function to display a menu
- A function to look up a person’s email address
- A function to add a new name and email address
- A function to change an email address
- A function to delete a name and email address.
This is the Required Output example:
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 2 Enter name: John Enter email address: John@yahoo.com That name already exists
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 2 Enter name: Jack Enter email address: Jack@yahoo.com Name and address have been added
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 1 Enter a name: Sam The specified name was not found
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 1 Enter a name: Jack Name: Jack Email: Jack@yahoo.com
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 3 Enter name: John Enter the new address: John@wayne.edu Information updated
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 1 Enter a name: John Name: John Email: John@wayne.edu
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 4 Enter name: Sam The specified name was not found
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 4 Enter name: Jack Information deleted
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 1 Enter a name: Jack The specified name was not found
Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program
Enter your choice: 5 Information saved >>> |
Please check the pictures and fix the code.
Upvote for following the required steps and working code. Thank You.
Working code, but it needs one more function(def) to display the menu as mention in the directions and it gives an error that needs to be fixed.
def func1(m):
name=input("Enter a name:")
if name in m:
print("Name: ",name)
print("Email: ",m[name])
else:
print("The specified name was not found")
def func2(m):
name=input("Enter name: ")
email=input("Enter email address: ")
if name in m:
print("That name already exists")
else:
m[name]=email
print("Name and address have been added")
return m
def func3(m):
name=input("Enter name: ")
email=input("Enter the new address: ")
if name in m:
m[name]=email
print("Information updated")
return m
def func4(m):
name=input("Enter name: ")
if name in m:
del m[name]
print("Information deleted")
return m
else:
print("The specified name was not found")
menu={}
flag=True
while(flag):
print("Menu")
print("----------------------------------------")
print("1. Look up an email address")
print("2. Add a new name and email address")
print("3. Change an existing email address")
print("4. Delete a name and email address")
print("5. Quit the program")
print()
n=int(input("Enter your choice: "))
if(n==1):
func1(menu)
elif(n==2):
menu=func2(menu)
elif(n==3):
menu=func3(menu)
elif(n==4):
menu=func4(menu)
elif(n==5):
print("Information saved")
flag=False
Upvote for adding one more function ''def'' and fixing the error from the already existing code.
ERROR:
Traceback (most recent call last):
File "C:/Users/17737/OneDrive/Desktop/Projectttt.py", line 52, in <module>
menu=func2(menu)
File "C:/Users/17737/OneDrive/Desktop/Projectttt.py", line 12, in func2
if name in m:
TypeError: argument of type 'NoneType' is not iterable
>>> TypeError: argument of type 'NoneType' is not iterable
SyntaxError: invalid syntax
>>>
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images