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
Person
andAddress
so that they can work well in a multiple-inheritance hierarchy
you may want to add
from superobject import SuperObject
to be able to use theSuperObject
class from lesson 06 -
implement the following classes:
class Contact
that inherits from bothAddress
andPerson
this class should have a
def show(self)
methodclass Notebook
that is a dictionary that maps people’s names to aContact
object. 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()