homework 10b create a class contact python program 10 18 the object contact here th 5151893

#Homework 10b – create a class – Contact

#python Program 10-18: The Object Contact
#Here the Object Class is defined.

class Contact:
#Define the constructor.
def __init__(self, name, phone, email):
self.name = name
self.phone = phone
self.email = email
def set__(self, name, phone, email):
self.name = name
self.phone = phone
self.email = email

def get__(self, name, phone, email):
self.name = name
self.phone = phone
self.email = email

#Define the function to return the details of the employees.
def __str__(self):
return self.name + “t” + “tt” + self.phone + “t” + self.email
import contact
import pickle

LOOK_UP = 1
ADD = 2
CHANGE = 3
DELETE = 4
SAVE = 5
QUIT = 6

#Global constant for the filename

FILENAME = 'contacts.dat'

def main():
mycontacts = load_contacts()
choice = 0
while choice != QUIT:
choice = get_menu_choice()
if choice == LOOK_UP:
look_up(mycontacts)
elif choice == ADD:
add(mycontacts)
elif choice == CHANGE:
change(mycontacts)
elif choice == DELETE:
delete(mycontacts)
save_contacts(mycontacts)

def load_contacts():
try:
input_file = open(FILENAME, 'rb')
contact_dct = pickle.load(input_file)
#close the phnone_inventory.dat file
input_file.close()
except IoError:
contact_dct = {}
return contact_dct
#The get_menue_choice fuction displays the menu
#and gets a validated choice from teh user.
def get_menu_choice():
print()
print('Menu')
print('——————————')
print('1. Look up a contact')
print('2. Add a new contact')
print('3. Change an an existing contact')
print('4. Delete contact')
print('5. Save contact')
print('6. Quit the program')
print()

choice = int(input('Enter the choice: '))
#validate choice
while choice < LOOK_UP or choice > QUIT:
choice = int(input(&#39; Enter a valid choice: &#39;))
return choice

def look_up(mycontacts):
name = input(&#39;Enter a name: &#39;)
print(mycontacts.get(name, &#39;Contact Not found.&#39;))

def add(mycontacts):
#get contact info
name = input(&#39;Enter name: &#39;)
phone = input(&#39;Enter phone number: &#39;)
email = input(&#39;Enter valid email: &#39;)
entry = contact.Contact(name, phone, email)

if name not in mycontacts:
mycontacts[name] = entry
print(&#39;That entry has been added. &#39;)
else:
print(&#39;That entry already exists. &#39;)

def change(mycontacts):
name = input(&#39;Enter name: &#39;)
if name in mycontacts:
phone = input(&#39;Enter phone number: &#39;)
email = input(&#39;Enter valid email&#39;)
entry = contact.Contact(name, phone, email)
  
#update
mycontacts[name] = entry
print(&#39;Information updated.&#39;)
else:
print(&#39;That name is not found. &#39;)
  
def save_contacts(mycontacs):
output_file = open(FILENAME, &#39;wb&#39;)
pickle.dump(mycontacts, output_file)   

def delete(mycontacts):
name = input(&#39;Enter name: &#39;)
if name in mycontacts:
del mycontacts[name]
print(&#39;Entry deleted. &#39;)   
else:
print(&#39;That name is not found. &#39;)
#close file   
output_file.close()

main()

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now