Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the method resolution order of class C.
Python
class A: pass class B: pass class C(A, B): pass print(C.[1]())
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'order' or 'methods'.
Trying to access an attribute instead of calling a method.
✗ Incorrect
The mro() method returns the method resolution order of a class.
2fill in blank
mediumComplete the code to define class C that inherits from classes A and B.
Python
class A: def greet(self): print('Hello from A') class B: def greet(self): print('Hello from B') class C([1]): pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of classes.
Inheriting from only one class instead of both.
✗ Incorrect
Class C inherits from A and B in that order, affecting the method resolution order.
3fill in blank
hardFix the error in the code to correctly call the greet method from class C.
Python
class A: def greet(self): print('Hello from A') class B: def greet(self): print('Hello from B') class C(A, B): pass c = C() c.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not exist like 'hello' or 'say_hello'.
Trying to call an attribute instead of a method.
✗ Incorrect
The method to call is greet, which is defined in classes A and B.
4fill in blank
hardFill both blanks to create a dictionary showing the MRO of class D and print it.
Python
class X: pass class Y: pass class D([1], [2]): pass print(D.mro())
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated class names like A or B.
Reversing the order of inheritance.
✗ Incorrect
Class D inherits from X and Y, so the MRO will reflect that order.
5fill in blank
hardFill all three blanks to create a class E that inherits from B and C, and print its MRO.
Python
class B: pass class C: pass class E([1], [2]): pass print([3].mro())
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names in inheritance or print statement.
Forgetting to call the mro() method.
✗ Incorrect
Class E inherits from B and C, and we print the MRO of E.