Payroll for the Whole Staff

Python for AIHard+10 XP+10

Payroll for the Whole Staff

A small company pays three kinds of staff every month. Build the family, then run the payroll.

Employee(name, salary) (the parent). salary is per year.

  • monthly_pay() returns salary / 12, rounded to 2 decimal places.

Manager(name, salary, bonus), a child of Employee. bonus is per year.

  • monthly_pay() returns the employee's monthly pay plus bonus / 12, rounded to 2 decimal places at the end.

Intern(name, stipend), a child of Employee. stipend is paid per month.

  • An intern's yearly salary is stipend * 12. Pass that up to the parent's __init__, so the parent's monthly_pay() works for interns without being overridden.

Then write two functions:

  • payroll(staff) returns a dictionary mapping each person's name to their monthly pay. Names are all different. An empty list gives {}.
  • payroll_total(staff) returns everyone's monthly pay added up, rounded to 2 decimal places. An empty list gives 0.

Examples

staff = [Employee("Ana", 36000), Manager("Raj", 60000, 6000)]
returns {'Ana': 3000.0, 'Raj': 5500.0}
staff = [Intern("Li", 1200), Employee("Ana", 36000)]
returns 4200.0
Intern("Li", 1200).salary
returns 14400

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run