title: how to display average attendance using a class in python
body: <p>I have the following code which has attempted to display the average attendance of all 'created' students. I have a studentCount that counts and prints all students in existence, but cannot seem to arrive at the logic that would do this for attendance. My attempt is below:</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>class Student: 
      studentCount=0
      attendanceAverage=0
  
      def __init__(self, name, form,special_interest,attendance, merits):  #additional variables added here such as special_interest, merits, attendance
          self.name=name
          self.form=form
          self.special_interest=special_interest #additions for the above made here
          self.attendance=attendance
          self.merits=merits
  
          Student.studentCount+=1
          Student.attendanceAverage=attendance/Student.studentCount
  
      def displayCount(self):
          print("Total Students:",Student.studentCount)
  
      def displayStudent(self): 
          print("=Name:",self.name,"=Form:",self.form,"Special Interest:",self.special_interest,"Attendance:",self.attendance,"Merits:",self.merits) #updating the print method for displayStudent to include additional variables
  
      def displayAttendance(self):
          print("=Name:",self.name,"=Attendance:",self.attendance)
  
  
  
  student1=Student("Student1","9F","Guitar",10,200) 
  student2=Student("Student2","9R","Chess",7,488) 
  student3=Student("Student3","9T","Dance",9,770)
  student1.displayStudent() 
  student2.displayStudent()
  student3.displayStudent()
  student3.displayAttendance()
  
  print("Average Attendance:",Student.attendanceAverage)
  print("Total Students:",Student.studentCount)  #prints a total count of students
  </code></pre>
  
  <p><strong>Current Output</strong> </p>
  
  <pre><code>=Name: Student1 =Form: 9F Special Interest: Guitar Attendance: 10 Merits: 200
  =Name: Student2 =Form: 9R Special Interest: Chess Attendance: 7 Merits: 488
  =Name: Student3 =Form: 9T Special Interest: Dance Attendance: 9 Merits: 770
  =Name: Student3 =Attendance: 9
  Average Attendance: 3.0
  Total Students: 3
  </code></pre>
  
  <p><strong>What is not working ..</strong></p>
  
  <p>The Average Attendance should obviously be an average of 10, 7 and 9 in this case. I have tried various things like below (trying to declare the sum of attendances first...after which I could calculate the average)...</p>
  
  <pre><code>    Student.attendanceCount=? #sum all the existing values for attendance
      Average=attendanceCount/Student.studentCount
  </code></pre>
  
  <p>This was an attempt to first sum the attendances of the various students, and then I would go on to average them. I cannot arrive at the syntax to do the first thing though (obtain all the values for each student). Is there a pythonic or best way to do so?</p>
  
  <p><strong>For an accepted answer</strong>, could someone please provide a suggested solution to the problem, with suitable comments and explanation as well as, if appropriate, any more elegant ways to solve the same problem. </p>