Extending behaviour with inheritance

Beginner Python OOP Inheritance
Created by Pavel · 07.03.2026 at 19:57 UTC · 5.0 (1 ratings) · 9 completed

When several pipelines share the same storage shape but differ in what happens on each write, inheritance lets you reuse the boring parts and override the interesting hook. GrowingContainer keeps the parent's list semantics yet adds a visible trace each time a value arrives.

Always call super() when you still need the parent's invariant work; the edge case is bypassing it and silently dropping data appends.

University approvals: 0
Tasks
Question 1

Which syntax correctly declares that a class inherits from another?

Hint

Parent name goes in parentheses

Question 2

Fill in GrowingContainer.add. DataContainer is already defined: __init__ sets self.name and self.data, and add appends to self.data. Override add so the parent still stores the value, then emit one line of the form Growing: <value> for the argument passed in (for example Growing: 42 when value is 42).

Grading: expression mode — your file is executed once; each test then evaluates one Python expression in that namespace (stdout or value as configured for the test).

Hint

Delegate with super().add(value) before printing; otherwise the list never grows.

Starter code is prefilled; replace TODO blocks with your solution.
2 test cases 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
  • Rating: 5.0 / 5.0
  • Completed: 9 users
Creator
Pavel
Pavel