Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python Multiple Inheritance and MRO Code

Practice multiple base classes, inspect the MRO, and build a cooperative super() chain.

Intermediate ~9 min read

Challenge 1

Complete the class definition so PrinterReport inherits from both Report and Printable.

python Your answer
class Report:
    def text(self):
        return "report"

class Printable:
    def print_text(self):
        return self.text()

class PrinterReport():
    pass

report = PrinterReport()
print(report.print_text())

Press Ctrl⌘Enter to check your answer

Challenge 2

Complete the expression so the list comprehension iterates over C's full method resolution order.

python Your answer
class A:
    pass

class B:
    pass

class C(A, B):
    pass

print([name.__name__ for name in ])

Press Ctrl⌘Enter to check your answer

Challenge 3

Complete Bottom.steps() so the cooperative chain continues to the next class in the MRO.

python Your answer
class Root:
    def steps(self):
        return ["root"]

class Left(Root):
    def steps(self):
        return ["left"] + super().steps()

class Right(Root):
    def steps(self):
        return ["right"] + super().steps()

class Bottom(Left, Right):
    def steps(self):
        return ["bottom"] + 

print(Bottom().steps())

Press Ctrl⌘Enter to check your answer

Challenge 4

Choose the direct base order that makes EmailSender participate before FileSender.

python Your answer
class EmailSender:
    def send(self):
        return "email"

class FileSender:
    def send(self):
        return "file"

class Notification():
    pass

print(Notification().send())

Press Ctrl⌘Enter to check your answer