Colab

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:

  1. Modify classes Person and Address 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 the SuperObject class from lesson 06

  2. implement the following classes:

  3. class Contact that inherits from both Address and Person

    this class should have a def show(self) method

  4. class Notebook that is a dictionary that maps people’s names to a Contact object. it doesnt need to inherit anything
    1. this class should have a def show(se) method
    2. this class should have a def add(self, name, email, street, city) method
  5. 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()