Multiple inheritance
given the following classes Address and Person:
class Address:
def __init__(self, street, city):
self.street = str(street)
self.city = str(city)
def show(self):
print(self.street)
print(self.city)
class Person:
def __init__(self, name, email):
self.name = name
self.email= email
def show(self):
print(self.name + ' ' + self.email)
Task:
- Modify classes
PersonandAddressso that they can work well in a multiple-inheritance hierarchy
you may want to add
from superobject import SuperObjectto be able to use theSuperObjectclass from lesson 06 -
implement the following classes:
class Contactthat inherits from bothAddressandPersonthis class should have a
def show(self)methodclass Notebookthat is a dictionary that maps people’s names to aContactobject. it doesnt need to inherit anything- this class should have a
def show(se)method - this class should have a
def add(self, name, email, street, city)method
- this class should have a
-
Test your code with the sample code below:
notes = Notebook() notes.add('Alice', '<alice@example.com>', 'Lv 24', 'Sthlm') notes.add('Bob', '<bob@example.com>', 'Rtb 35', 'Sthlm') notes.show()expected output:
Alice <alice@example.com> Lv 24 Sthlm Bob <bob@example.com> Rtb 35 Sthlm
### useful test for your code
notes = Notebook()
notes.add('Alice', '<alice@example.com>', 'Lv 24', 'Sthlm')
notes.add('Bob', '<bob@example.com>', 'Rtb 35', 'Sthlm')
notes.show()