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
Among the many DTP software tools available today, which is regarded as the industry standard for DTP?
nexus9112 [7]

Answer:

bland1 InDesign    Blank2 typesetting

Explanation:

4 0
3 years ago
Read 2 more answers
5. The coordinates of triangle ABC are A(-7, 3), B(3, -7) and C(8. 8)
kati45 [8]

Answer:

b

Explanation:

6 0
3 years ago
Read 2 more answers
Can you withdraw from courses in top hat?
ad-work [718]

Answer:

Yes, but this must be done before the withdraw deadline

Explanation:

TopHat is an online learning platform. Students register for courses and if they decide not to continue with a course for reasons best known to them, they are allowed a time period usually one to two weeks to drop the courses. They are then reimbursed the fee for that particular course.

But if that time period elapses and they drop the course, that is considered a withdrawal that is not accepted and which no provisions for reimbursements are made.

7 0
2 years ago
What is x squared times b squared
Pie

Answer:

x^2 * b^2

Explanation:

Like 3 squared times 2 squared is 3*3*2*2. Similarly the expression given in the question is equal to x*x*b*b. And that explains what is mentioned in question.

3 0
3 years ago
Why are rules required for a number system to be useful?
evablogger [386]

Answer

This is because without them no one would know how much each symbol represents, and no one would be able to decipher the message.

Explanation

Number system is a way to represent numbers. It  is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.

In computing or in a computer number systems are the techniques which represents numbers in the computer system architecture where   every value that you are saving or getting into/from computer memory has a defined number system.Computer architecture supports  . Binary number system,Octal number system and Decimal number system.

5 0
3 years ago
Read 2 more answers
Other questions:
  • When you send an echo request message with the ping program, a successful attempt will return a(n) ______ message.
    8·1 answer
  • The counter variable in the code below increments by 1 each time through the loop. What will the value of counter be after the f
    11·1 answer
  • Write a function named firstLast2 that takes as input an array of integers and an integer that specifies how many entries are in
    14·1 answer
  • How Oracle 12c advances the security discussion?
    12·1 answer
  • ANYONE GOOD WITH CODING IN C++
    14·1 answer
  • Jasmine wants electrical current to be able to pass through a certain switch on a circuit board that she is designing. What stat
    5·1 answer
  • Of the following field which would be the most appropriate for the primary key in a customer information table?
    5·1 answer
  • For how long should a media piece hold the user's attention?
    13·2 answers
  • What plan can businesses use to protect sensitive data from malicious attacks?
    11·2 answers
  • Why is quantum computing potentially a better fit for weather forecasting than classical computers?.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!