Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Extend Parent __init__ with Extra Attributes

Practice using super() in a subclass __init__ to reuse parent initialization and add new attributes.

Python practice17 minInheritance & PolymorphismIntermediateLast updated April 8, 2026

Problem statement

You are provided with a Person class that stores name and age. Create an Employee subclass that extends Person. Employee.__init__ should call the parent's __init__ using super() to initialize name and age, then set two extra attributes: employee_id and role. Implement Employee.summary() to return a concise string combining all attributes in the format: "<name> (<age>) - <role> #<employee_id>". Finally, implement a helper function create_employee_summary(name, age, employee_id, role) that creates an Employee and returns its summary string.

Task

Implement a subclass that calls the parent's __init__ via super(), then sets additional attributes; provide a method that summarizes all attributes.

Examples

Employee creation

Input

create_employee_summary('Jane', 30, 42, 'Engineer')

Output

Jane (30) - Engineer #42

Employee.__init__ should call Person.__init__ for name and age, then store employee_id and role. summary() composes the final string.

Input format

Four values: name (str), age (int), employee_id (int), role (str).

Output format

A single string: "<name> (<age>) - <role> #<employee_id>".

Constraints

Use super() to call the parent's __init__. Do not reassign name or age directly without using the parent's initialization.

Samples

Sample 1

Input

create_employee_summary('Lee', 45, 7, 'Manager')

Output

Lee (45) - Manager #7

The employee summary formatting.