Question 13
Back to Exercise
What is the output of the following Python program?
class A:
def total(self): return 1
class B(A):
def total(self): return super().total() + 10
class C(B):
def total(self): return super().total() + 100
print(C().total(), B().total(), [k.__name__ for k in C.__mro__][:3])
- A 111 11 ['C', 'B', 'A'] Correct
- B 100 10 ['C', 'B', 'A']
- C 111 11 ['A', 'B', 'C']
- D 101 11 ['C', 'B', 'A']
Correct Answer: Option A
Each level adds to the result of the level above: 1 + 10 + 100.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!