OneCompiler

studentDB

251

'''
Task 4
1. Develop a class called Student
2. with attributes name, age, and grades,
3. and methods to calculate the average grade
4. and display student information.
'''

class Student:
    def __init__(self, name, age, grades):
        self.name = name
        self.age = age
        self.grades = grades

    def get_average(self):
        total = 0
        for subject in self.grades:
            total += self.grades[subject]
        avg = total / len(self.grades)
        return avg

    def info(self):
        print(f"Name: {self.name}\n"
              f"Age: {self.age}\n"
              f"Grades: {self.grades}\n"
              f"Average grade is: {Student.get_average(self)}\n")


marks = {
    "Math": 5.0,
    "Science": 4.7,
    "Engineering": 4.2,
    "Technology": 4.5
}
student1 = Student(age=21, grades=marks, name="Abdulla Qahhorov")
average = student1.get_average()
print("Average is: ", average)
student1.info()