Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Implement Base and Derived ClassesE02. Override a Method in a SubclassE03. Use super() to Call Parent __init__E

Problem No 3

Use super() to Call Parent __init__

Easy

8 minute session

Summary

Learn how to call a parent class __init__ from a subclass using super() to inherit and extend initialization.

Problem statement

You are given a Person base class that stores name and age and a Student subclass that should extend Person by adding a school attribute. Implement Student.__init__ so it calls the parent Person.__init__ using super() to initialize name and age, then sets the school attribute. Also implement make_student_summary(name, age, school) which creates a Student and returns the student's summary string from Student.summary().

Task

Implement a subclass __init__ that correctly calls the parent class __init__ with super(), then add subclass-specific attributes.

Examples

Create a Student summary

Input

make_student_summary("Alice", 20, "MIT")

Output

Alice is 20 years old and studies at MIT

Explanation

Student.__init__ should call Person.__init__ to set name and age; Student.summary() adds the school information.

Input format

A call to make_student_summary(name: str, age: int, school: str).

Output format

A single string with the student's summary.

Constraints

name and school are strings. age is an integer (may be 0 or negative for testing). Do not modify the Person.summary implementation; extend via Student.__init__ and Student.summary.

Samples

Sample input 0

make_student_summary("Bob", 18, "High School")

Sample output 0

Bob is 18 years old and studies at High School

Explanation 0

Simple case: Student inherits name and age from Person and adds school.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

03:45 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.