1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Jlenok [28]
1 year ago
13

write a program that keeps names and email addresses in a dictionary as key-value pairs. the program should display a menu that

lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. the program should save the data stored in a dictionary to a file when the user exits the program. each time the program starts, it should retrieve the data from the file and store it in a dictionary. the program should include the following functions: a. a function to display a menu. b. a function to look up a person’s email address. c. a function to add a new name and email address. d. a function to change an email address. e. a function to delete a name and email address. f. a function to load emails from a file. g. a function to save emails in a file. h. write main function with a loop that displays the menu allowing the user to select an operation from the menu; the program continue until the user enter 5. i. validate all user input. your program should check user input; for example, if the user wants to search or delete a name that does not exist in the dictionary, you should print something like the name is not in the database. if the user selects invalid operation from the menu, the program prints an error and allows the user to renter a valid operation; the program continue asking for a valid operation until a user selects a valid operation.
Computers and Technology
1 answer:
erma4kov [3.2K]1 year ago
3 0

To write a program that keeps names and email addresses in a dictionary as key-value pairs check the code given below.

<h3>What is key-value pairs?</h3>

In a key-value pair, two related data elements are combined: a value, which is a variable that belongs to the set (for example, male/female, green, 100), and a key, which is a constant that defines the data set (for example, gender, color, price).

A key-value pair could look something like this when fully formed:

gender = male

color = green

price > 100

↓↓↓//<u>Python code</u>//↓↓↓

import pickle

import sys

try:

   f=open('email.dat','rb')

   d=pickle.load(f)  

   f.close()

     

except:    

   d={}

while True:

   print('\n1. Find a email address')

   print('2. Add name and email address')

   print('3. Change an email address')

   print('4. Delete an email address')

   print('5. Exit\n')

   choice=input('\nEnter a choice: ')

   if choice:

       choice=int(choice)

   else:

       print('\nEnter a number')

       continue    

   if choice == 1:

       while True:

           name=input('\nEnter the name ')

           if name:

               if name in d:

                   print('\n%s is the email id of %s \n' % (d[name],name))

                   break

               else:

                   print('\n Email not found \n')

                   break

           else:

               print('\nName cannot be empty\n')

               continue

           

   elif choice==2:

       while True:            

       

           name=input('\nEnter the name ')

           if name:

               break;

           else:

               print('\nName cannot be empty \n')

               continue

       while True:            

       

           email=input('\nEnter the email address ')

           if email:

               d[name]=email

               break

           else:

               print('\nEmail cannot be empty\n')

               continue

           

   elif choice==3:

       while True:            

       

           name=input('\nEnter the name to change the email address ')

           if name:

               if name in d:

                   email=input('\nEnter the new email address ')

                   d[name]=email

                   print('\nEmail address changed \n')

                   break;

               else:

                   print('\nName not found \n')

                   break

           else:

               print('\nName cannot be empty \n')

               continue

           

   elif choice == 4:

       while True:            

       

           name=input('\nEnter the name to remove ')

           if name:

               if name in d:

                   del d[name]

                   print('\nName and Email address removed \n ')

                   break;

               else:

                   print('\nName not found \n')

                   break

           else:

               print('\nName cannot be empty\n')

               continue

   elif choice == 5:

       

       f=open('email.dat','wb')

       pickle.dump(d,f)

       f.close()

       sys.exit()

   else:

       print('\nEnter a valid choice ')    

Learn more about key-value pair

brainly.com/question/29414672

#SPJ1

You might be interested in
Why is Apple using social media ?
jeka57 [31]

Apple uses social media to promote their products and increase user-engagement. This is a very effective method of advertising.

6 0
3 years ago
বর্তমান করােনার ন্যায় পরিস্থিতি অর্থাৎ স্বাভাবিক শ্রেণি কার্যক্রম পরিচালনা সম্ভব
Zarrin [17]

Answer:

ayo fam

Explanation:

I dont think this is supposed to be here lol

5 0
3 years ago
Read 2 more answers
Mitchell doesn’t have a checking account, but needs to pay a bill, what can Mitchell pay with?
aleksandr82 [10.1K]
Cash, possibly credit card.
5 0
3 years ago
Read 2 more answers
What's the difference between natural systems and man made systems <br>​
Aneli [31]

Answer:

Natural systems are already in place while man made systems were created by humans manipulating things in some way.

Explanation:

man made: human created

natural systems: existed without interference

5 0
2 years ago
1. Felipe looks over his presentation, and he notices that some of his words are written in bold and some are written in italic.
romanna [79]
 <span>Felipe looks over his presentation, and he notices that some of his words are written in bold and some are written in italic.</span>His ability to remember these differences is an example of Retroactive encoding. Even though you didn't share the options, I am pretty sure this one will help!

4 0
2 years ago
Other questions:
  • Test Average and Grade
    12·1 answer
  • *hacked*
    12·1 answer
  • What is structured​ knowledge?
    10·1 answer
  • The first step to changing lanes is
    8·2 answers
  • 1. provide at least 3 properties and 3 methods of the object computer.
    8·1 answer
  • Why is it generally a good idea to set the font size to at least 30 points in presentations?
    6·2 answers
  • 1. Why do you need to take care of your computer? (Remember: Answer must include 3-5 sentences.)
    13·1 answer
  • Zybook C++ 3.21 answer
    9·1 answer
  • Define the computer with its workintg principple
    7·1 answer
  • What does an arrow after a command indicate
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!