Write four classes: Address, Person, Contact, and Notebook.
Address takes as parameters the street name and city. A person has a name and email address. Both classes have methods to print the information.
Derive the Contact class from Address and Person. Use their methods to print the information for a contact.
In the Notebook class, create a dictionary named person to store the contact information (name as key, <name, email, street, city> as value). Create a method to print the information for the called person. If the name is not found in the dictionary, print Unknown.
class Address:
def __init__(self, street, city):
self.street = street
self.city = city
def DisplayAddress(self):
print("street is:", street, "city is:", city)
def GetStreet(self):
return street
def GetCity(self):
return city
class Person:
def __init__(self, name, email):
self.name = name
self.email = email
def DisplayPerson(self):
print("Name is:", name, "email is:", email, end = " ")
def GetName(self):
return name
def GetEmail(self):
return email
class Contact(Address, Person):
def DisplayContact(self):
self.DisplayPerson
self.DisplayAddress
class Notebook(Contact):
person = {}
def __init__(self):
person = {}
def AddPerson(self, name, email, street, city):
self.person[name] = [email, city, street]
def DisplayInfo(self, quest):
if quest in self.person:
print(quest, self.person.get(quest))
else:
print("Unknown")
Note = Notebook()
Note.AddPerson("Bill", "Bill@gmail.com", "Green street", "Slidell")
Note.DisplayInfo("Bill")
Note.DisplayInfo("Bil")
Comments
Leave a comment