Payroll Across a Class Hierarchy

Medium ⏱ 12 min 60% acceptance ★★★★★ 4.5
Staff(name, base) computes monthly_pay() as base. SalesRep(Staff) adds a commission and overrides monthly_pay() to base + commission; Contractor(Staff) overrides to base * 0.9 (retention withheld). Write payroll(staff_list) summing everyone's pay polymorphically.

Examples

Example 1
Input
payroll([Staff('a', 100), SalesRep('b', 100, 50), Contractor('c', 100)])
Output
340.0
Explanation

100 + 150 + 90.

Constraints

  • Subclasses call super().__init__.
  • payroll has no type checks.

Topics

OOPinheritance + polymorphism

Companies

DeloitteAccentureInfosys

Hints

Hint 1

Each override is one line of arithmetic.

Hint 2

sum over monthly_pay() calls.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.