Need code written in PYTHON please. Thank you! Write a program that keeps names
ID: 3680471 • Letter: N
Question
Need code written in PYTHON please. Thank you!
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 pickle* the dictionary and save it to a file when the user exits the program. Each time the program starts, it should retrieve the dictionary from the file and unpickle* it.
You must request for a file name from the user and deal with file ‘exceptional’ situations. Your program must have at least 5 meaningful functions.
• display a menu
• look up a person’s email address
• add a new name and email address
• change an existing email address
• delete an existing name and email address.python
Thank you! Python please.
Explanation / Answer
#!/usr/bin/python
from Tkinter import *
# import the libraries
# dictionary routine in python
# key value pairs
# name, email addresses
# intitally the dictionary has nothing
dictionary1 = {}
dictionary1['Name1'] = 'Jack'
dictionary1['Name2'] = 'Jill'
dictionary1['Name3'] = 'John'
dictionary1['Name4'] = 'Jamima'
dictionary1['Name5'] = 'Jaimie'
dictionary1['Name6'] = 'Jim'
dictionary1['Name7'] = 'Melanie'
dictionary1['Email1'] = 'Jack@chegg.com'
dictionary1['Email2'] = 'Jill@chegg.com'
dictionary1['Email3'] = 'John@chegg.com'
dictionary1['Email4'] = 'Jamima@chegg.com'
dictionary1['Email5'] = 'Jaimie@chegg.com'
dictionary1['Email6'] = 'Jim@chegg.com'
dictionary1['Email7'] = 'Melanie@chegg.com'
# now read the name and emails from user and use the variable names
# put inside a loop so that it will run untill the user chooses the exit option
while (option != 'Exit'):
mesg = "Enter user name"
name = input(mesg)
mesg = "Enter email address for the user: " + name
email = input(mesg)
dictionary[Name] = name
dictionary[Email] = email
dictionary1 = {'Name': 'Jack', 'Email': 'JacksEmailAddress'}
# throw a menu for the user to look up email
# or search for email for the given name
# add new name
def functionAddNewName():
mesg = "Please enter the name"
name = input(mesg)
# add new email address
# change email for an existing name
# delete an existing name along with his/her email address
root = Tk()
menuTab = Menu(root)
dictionaryMenu = Menu(menuTab, tearoff=0)
dictionaryMenu.add_command(label="addNewName", command=functionAddNewName)
dictionaryMenu.add_command(label="addNewEmail", command=functionAddNewEmail)
dictionaryMenu.add_command(label="ChangeEmail", command=functionChangeEmail)
dictionaryMenu.add_command(label="deleteNameAndEmail", command=functionDeleteNameAndEmail)
dictionaryMenu.add_command(label="lookUpEmail", command=functionlookUpEmail)
# Dict = Dictionary
dictionaryMenu.add_command(label="ExitAndPickleTheDictionary", command=functionExitAndPickleDict)
# assumption made for the word pickle:
# pickle the dictionary = store and preserve the dictionary in the file or data base
# unpickle the dictionary = read out the dictionary from the data base file
# read file name from the user
from Tkinter import *
# import the libraries
# dictionary routine in python
# key value pairs
# name, email addresses
# throw a menu for the user to look up email
# or search for email for the given name
# add new name
# add new email address
# change email for an existing name
# delete an existing name along with his/her email address
root = Tk()
menuTab = Menu(root)
dictionaryMenu = Menu(menuTab, tearoff=0)
dictionaryMenu.add_command(label="addNewName", command=functionAddNewName)
dictionaryMenu.add_command(label="addNewEmail", command=functionAddNewEmail)
dictionaryMenu.add_command(label="ChangeEmail", command=functionChangeEmail)
dictionaryMenu.add_command(label="deleteNameAndEmail", command=functionDeleteNameAndEmail)
dictionaryMenu.add_command(label="lookUpEmail", command=functionlookUpEmail)
# Dict = Dictionary
dictionaryMenu.add_command(label="ExitAndPickleTheDictionary", command=functionExitAndPickleDict)
# assumption made for the word pickle:
# pickle the dictionary = store and preserve the dictionary in the file or data base
# unpickle the dictionary = read out the dictionary from the data base file
# read file name from the user
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.