Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Create a Simple ClassE02. Instantiate an ObjectE03. Implement a ConstructorE

Problem No 3

Implement a Constructor

Easy

10 minute session

Summary

Learn to write an __init__ method to initialize instance attributes when an object is created.

Problem statement

Create a class Student with a constructor that accepts name and grade and stores them on the instance as .name and .grade. Implement a method is_passing(self) that returns True when grade is greater than or equal to 60, otherwise False. The grade may be an integer or float; simply compare numerically.

Task

Implement a constructor that sets instance attributes and a method that uses those attributes.

Examples

Create and check passing

Input

s = Student('Alice', 85) s.name, s.grade, s.is_passing()

Output

('Alice', 85, True)

Explanation

Constructor sets name and grade attributes; is_passing returns True for grade >= 60.

Input format

No direct input; learner defines the Student class. Tests will construct Students and call attributes/methods.

Output format

Accessing .name returns the name string. is_passing() returns a boolean.

Constraints

Store the grade exactly as provided (do not coerce to int unless given). Compare numerically using >= 60.

Samples

Sample input 0

Student('Bob', 59).is_passing()

Sample output 0

False

Explanation 0

Grade 59 is below the passing threshold.

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:42 PM

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