Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to call the parent class method inside the child class.
Python
class Parent: def greet(self): print("Hello from Parent") class Child(Parent): def greet(self): [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling self.greet() causes infinite recursion.
Calling Parent.greet() without self argument causes error.
Calling greet() alone is undefined.
✗ Incorrect
Using super().greet() calls the parent class method correctly from the child class.
2fill in blank
mediumComplete the code to extend the parent method by adding extra behavior in the child class.
Python
class Parent: def show(self): print("Parent show") class Child(Parent): def show(self): [1] print("Child show")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling self.show() causes infinite recursion.
Calling Parent.show(self) works but is less flexible.
Calling show() alone causes error.
✗ Incorrect
super().show() calls the parent method properly, allowing the child to add extra behavior.
3fill in blank
hardFix the error in the child class method to properly extend the parent method.
Python
class Parent: def info(self): print("Info from Parent") class Child(Parent): def info(self): [1] print("Info from Child") c = Child() c.info()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling self.info() causes infinite recursion.
Calling Parent.info() without self argument causes error.
Calling info() alone is undefined.
✗ Incorrect
Using super().info() correctly calls the parent method without causing recursion.
4fill in blank
hardFill both blanks to extend the parent method and add a new message in the child class.
Python
class Animal: def speak(self): print("Animal speaks") class Dog(Animal): def speak(self): [1] print([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Animal.speak(self) works but is less flexible than super().speak().
Printing the wrong message confuses output.
Not calling the parent method misses inherited behavior.
✗ Incorrect
super().speak() calls the parent method, and printing "Dog says woof" adds child behavior.
5fill in blank
hardFill all three blanks to extend the parent method, add a new message, and call another parent method.
Python
class Vehicle: def start(self): print("Vehicle started") def stop(self): print("Vehicle stopped") class Car(Vehicle): def start(self): [1] print([2]) [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling Vehicle.start(self) works but is less flexible than super().start().
Not calling super().stop() misses stopping behavior.
Printing wrong message confuses output.
✗ Incorrect
super().start() calls the parent's start, printing the car message adds child behavior, and super().stop() calls the parent's stop method.