Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Build a Student Record Class

Implement a Student class with common behaviors: full name, grade management, GPA calculation, and honors detection.

Python practice15 minClasses & Objects FundamentalsIntermediateLast updated April 7, 2026

Problem statement

Create a Student class to model a simple student record. The class should store a student's first and last name, an optional list of numeric grades (0.0 - 4.0 scale), and an optional student_id. Implement methods to return the student's full name, add a grade with validation, compute the GPA (average) rounded to two decimal places, return a letter grade based on the GPA, and determine if the student qualifies for honors. The add_grade method should return True when a valid grade is added and False for invalid inputs. The average method should return 0.0 when there are no grades.

Task

Learn to design a Python class with a constructor, instance attributes, instance methods, input validation, and simple business logic (GPA rounding and letter grade mapping).

Examples

Compute GPA and honors

Input

s = Student('Ana', 'Bell', [4.0, 3.7]) s.average()

Output

3.85

Average of [4.0, 3.7] is (4.0 + 3.7)/2 = 3.85. The method returns the value rounded to 2 decimals.

Input format

You will construct Student objects and call instance methods. Examples: Student('John', 'Doe', [3.0, 4.0]).average()

Output format

Methods return values (strings, floats, or booleans). The test harness evaluates expressions and compares their string representation to the expected output.

Constraints

Grades must be numeric values between 0.0 and 4.0 inclusive. average() returns a float rounded to 2 decimal places. If there are no grades, average() must return 0.0. add_grade should return True when a grade is added, False otherwise. No external libraries.

Samples

Sample 1

Input

Student('John','Doe',[3.0,4.0,3.7]).letter_grade()

Output

B

The average is 3.57, which maps to letter grade 'B' with the mapping: A >= 3.7, B >= 3.0, C >= 2.0, D >= 1.0, else F.