code that allows to input score of five students but how to add the score of all the students

Viewed 145

I am a newbie who just learnt about functions and classes. I created a code using Class with a while loop that allows the entry of marks of five students in four subjects. Now I don't know how to add up the avg scores of all students and find the overall average score of the five students combined. I am providing the full code here. Please suggest all the improvements and solution to the problem.

entry = 1
while entry <=5:
    class Marks():
            def __init__(self, name, english_marks, hindi_marks, science_marks, economics_marks):
                self.name = name
                self.english_marks = english_marks
                self.hindi_marks = hindi_marks
                self.science_marks = science_marks
                self.economics_marks = economics_marks
            def output(self):
                print("\n")
                print("Hi "+self.name.title())
                avg_marks = (self.english_marks + self.hindi_marks + self.science_marks + self.economics_marks)/4
                print("Your average score is ", avg_marks)
                print("\n")
        
    name = input("Enter your name: ")
    english_marks = int(input("Enter your English score: "))
    hindi_marks = int(input("Enter your Hindi score: "))
    science_marks = int(input("Enter your science score: "))
    economics_marks = int(input("Enter your economics score: "))
        
    j = Marks(name, english_marks, hindi_marks, science_marks, economics_marks)
    j.output()
    entry = entry + 1
        
1 Answers

updated

Use the average values from each student to make a variable that averages the values (you can make the five avg_marks variables in the output function based on what your entry value is.)

example:

total =(avg_marks1+avg_marks2+avg_marks3+avg_marks4+avg_marks5)/5
Related