In this Python oops program, we will create a Python class example. Python class called StudentRecord with attributes name, age, and grades.
Python class example
Steps to solve the program
- The StudentRecord class has a constructor method __init__ that takes three parameters: name, age, and grades. It initializes the instance variables self.name, self.age, and self.grades with the provided values.
- The class also has a method called calculate_average_grade which calculates the average grade of the student. It sums up all the grades in the self.grades list, divides it by the number of grades, and returns the average grade.
- The print_details method prints the student’s name, age, and average grade by calling the calculate_average_grade method.
- The code creates an object student of the StudentRecord class with the name “John Snow”, age 20, and a list of grades [80, 90, 85, 95].
- The print_details method is called on the student object, which prints the student’s details, including their name, age, and average grade.
- Thus, we have created a Python class example.
Output:
Related Articles
Create a Python class called Course with attributes name, teacher, and students.
Create a Python class called Shape with a method to calculate the area of the shape.
Create a Python class called Employee with attributes name and salary.
Create a Python class called Manager that inherits from the Employee class.
Create a Python class called Customer with attributes name and balance.
Create a Python class called VIPCustomer that inherits from the Customer class.