Answer to Question #282594 in Python for jennn

Question #282594

I have a problem of solving to get the average of 1st quarter, 2nd quarter, 3rd quarter and 4th quarter of list and this is the code.

class Students:

  def __init__(self):

    self.studName = []

    self.gender = []

    self.stQ = []

    self.ndQ = []

    self.rdQ = []

    self.thQ = []

  def newStudent(self,newStud,studGender):

    self.studName.append(newStud)

    self.gender.append(studGender)

  def studGrades(self,first,second,third,fourth):

    self.stQ.append(first)

    self.ndQ.append(second)

    self.rdQ.append(third)

    self.thQ.append(fourth)

    print("Student Grade 1st Quarter: ", first)

    print("Student Grade 2nd Quarter: ", second)

    print("Student Grade 3rd Quarter: ", third)

    print("Student Grade 4th Quarter: ", fourth)

  #average

  def Average(self):

    for i in self.stQ,self.ndQ,self.rdQ,self.thQ:

      sums = self.stQ[i] + self.ndQ[i] + self.rdQ[i] + self.thQ[i]

      avg = sums / 4

      print(avg)


1
Expert's answer
2021-12-27T08:41:28-0500
class Students:
    def __init__(self):
        self.studName = []
        self.gender = []
        self.stQ = []
        self.ndQ = []
        self.rdQ = []
        self.thQ = []


    def newStudent(self, newStud, studGender):
        self.studName.append(newStud)
        self.gender.append(studGender)


    def studGrades(self, first, second, third, fourth):
        self.stQ.append(first)
        self.ndQ.append(second)
        self.rdQ.append(third)
        self.thQ.append(fourth)
        print("Student Grade 1st Quarter: ", first)
        print("Student Grade 2nd Quarter: ", second)
        print("Student Grade 3rd Quarter: ", third)
        print("Student Grade 4th Quarter: ", fourth)


    # average


    def Average(self):
        for i in range(len(self.stQ)):
            sums = self.stQ[i] + self.ndQ[i] + self.rdQ[i] + self.thQ[i]
            avg = sums / 4
            print(avg)



obj = Students()
obj.newStudent("Will", "male")
obj.studGrades(85, 77, 90, 100)
obj.Average()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS