super()
Completed
Create Employee(name, salary) with describe() returning NAME earns SALARY, and Manager(name, salary, team) that calls super().__init__ and extends describe() with and manages TEAM people. Read both and print each description.
Input
Line 1: employee name salary. Line 2: manager name salary team.
Output
Two lines.
Example
Input
ann 50000 bob 90000 6
Output
ann earns 50000 bob earns 90000 and manages 6 people
Editor
Python
Hints
super().__init__(...) runs the parent constructor.
super().describe() reuses the parent method's text.
Solution explanation
super() lets a subclass extend, rather than copy, its parent's behaviour.
Show solution
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary
def describe(self):
return f"{self.name} earns {self.salary}"
class Manager(Employee):
def __init__(self, name, salary, team):
super().__init__(name, salary)
self.team = team
def describe(self):
return super().describe() + f" and manages {self.team} people"
name, salary = input().split()
print(Employee(name, int(salary)).describe())
name, salary, team = input().split()
print(Manager(name, int(salary), int(team)).describe())