Overriding parent methods

Beginner Python OOP Inheritance
Created by Pavel · 07.03.2026 at 19:57 UTC · 3 completed

Overriding replaces the parent's method body while keeping the name familiar to callers. Cleaning pipelines often clamp negatives to zero, then clamp large positives—each stage can call super() to reuse the previous guarantee.

The subtle bug is enforcing only the child's rule and never invoking the parent, which duplicates logic and drifts when the parent changes. Another edge case is types: if clean must tolerate non-numeric input, document or validate before comparing.

University approvals: 0
Tasks
Question 1

What term describes a child class redefining a parent method?

Hint

Common term in OOP textbooks

Question 2

ValueCleaner.clean(self, x) returns x if x >= 0 else 0.
StrictCleaner(ValueCleaner).clean(self, x) uses val = super().clean(x) then returns val if val <= 100 else 100.
c = StrictCleaner() then print(c.clean(-3), c.clean(60), c.clean(180)) space-separated.

Expected stdout: 0 60 100.

Hint

Call super().clean inside StrictCleaner.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Python OOP Inheritance
  • Difficulty: Beginner
  • Completed: 3 users
Creator
Pavel
Pavel