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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 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.

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
>>>

BE1600 - Project -
*Python 3.8.4 Shell*
ff
File Edit Shell Debug Options Window Help
Refere
4. Delete a name and email address
me
Insert
Design
Layout
write the data in the dictionary in a file 5. Quit the program
Enter your choice: 2
Enter name: John
This is the Required Output example:
Enter email address: John@yhaoo.com
Name and address have been added
Menu
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
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 your choice: 2
Enter name: John
Enter email address: John@yhaoo.com
That name already exists
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
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@yhaoo.com
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:
Enter your choice: 2
Enter name: Jack
Enter email address: Jack@yahoo.com
Name and address have been added
Menu
TypeError: argument of type 'NoneType' is not iterable
>>> TypeError: argument of type 'NoneType' is not iterable
SyntaxError: invalid syntax
1. Look up an email address
>>>
2. Add a new name and email address
>>>
3. Change an existing email address
>>>
>>> Do not modify the code just add another function def and fix the error. Upvote for working code.
Transcribed Image Text:BE1600 - Project - *Python 3.8.4 Shell* ff File Edit Shell Debug Options Window Help Refere 4. Delete a name and email address me Insert Design Layout write the data in the dictionary in a file 5. Quit the program Enter your choice: 2 Enter name: John This is the Required Output example: Enter email address: John@yhaoo.com Name and address have been added Menu 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 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 your choice: 2 Enter name: John Enter email address: John@yhaoo.com That name already exists 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 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@yhaoo.com 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: Enter your choice: 2 Enter name: Jack Enter email address: Jack@yahoo.com Name and address have been added Menu TypeError: argument of type 'NoneType' is not iterable >>> TypeError: argument of type 'NoneType' is not iterable SyntaxError: invalid syntax 1. Look up an email address >>> 2. Add a new name and email address >>> 3. Change an existing email address >>> >>> Do not modify the code just add another function def and fix the error. Upvote for working code.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education