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
Which of the following is the single best rule to enforce when designing complex passwords?
saw5 [17]

Answer:

B. Longer passwords

Explanation:

If the password is longer, it requires more incorrect attempts to find it, so the system could identify a potential hacker attempt. Smaller but more complex passwords could be identified by mistype or forgotten passwords.

3 0
2 years ago
Higher resolution images mean they can be enlarged better, <br> True or false
ella [17]

Answer:

False

Explanation:

High resolution just mean It looks better

6 0
3 years ago
Read 2 more answers
Need some help writing a simple PYTHON Student registration program:
Y_Kistochka [10]

import random

database = {}

while True:

   try:

       user_choice = int(input("Enter your student id to bring up your information (Press enter if you don't have one) : "))

       if user_choice in database:

           print("Student ID:",database[user_choice][0],"\nFirst name:",database[user_choice][1],"\nLast name:",database[user_choice][2],"\nPhone number:",database[user_choice][3],"\nEmail address:",database[user_choice][4],"\nPassword:",database[user_choice][5],"\nPoints:",database[user_choice][6])

   except ValueError:

       name = input("Enter your first name: ")

       last_name = input("Enter your last name: ")

       phone_number = input("Enter your phone number: ")

       email = input("Enter your email address: ")

       password = input("Enter a password: ")

       points = 100

       student_id = random.randint(1,1000)

       while student_id in database:

           student_id = random.randint(1,1000)

       print("Hello,",name,"your student ID is:",student_id)

       database[student_id] = [student_id,name, last_name, phone_number, email, password, points]

I wrote my code in python 3.8. I hope this helps.

6 0
2 years ago
What should my school do? someones been trying to hack the wifi and computers here.
Snezhnost [94]

they should have a fund raiser and collect money and then put up strong fire walls on all the computers

5 0
2 years ago
The analog computer deals directly with
marta [7]

continuously variable aspects of physical phenomena such as a electrical, mechanical etc.

4 0
3 years ago
Read 2 more answers
Other questions:
  • Five computers are connected to a switch in a star topology. what type of network is this?
    12·1 answer
  • Kendall receives an email stating that a leading computer company is giving away free computers, asking her to forward the email
    15·1 answer
  • Oday's color display devices represent color using the ______ color model.â
    13·1 answer
  • How can you autohide the taskbar in Windows 10?
    8·2 answers
  • An email address contains the @ character. Write a program that takes asks for an email address input from the user and determin
    5·1 answer
  • What symbol do you use to choose a feature for your notes on Notion?
    8·1 answer
  • Write a MATLAB program to accomplish the following: Create two vectors, a and b, where vector a contains all positive integers l
    10·1 answer
  • What special signal is issued periodically from an Access Point and contains the network transmission rate and service set ident
    7·1 answer
  • What is "mob of the dead"?
    7·1 answer
  • Employees in your organization regularly need to print sensitive documents. The employees properly dispose of the hard copies of
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!