Python Classes Review - Further Practice Discussion

Edit 2: I added a line of code to return a different message for a student with perfect attendance.

Edit 1: I figured out how to do what I was wanting which was to keep count of the number of absences. I converted the boolean values to integers then counted the number of ‘False’ values.

I figured out how to manipulate the different data the way I want to, I think. However, can someone please help me figure out how get my absence counter to work? It works for Pieter because he only has 1 absence, but it also says that Roger has 1 absence when he has 2. I’m sure it’s simple, but my brain is FRIED! I will edit later after I’ve worked on it some more. I think I need to review the options I have for working with the list of values in a dictionary. And I might have just answered my own question…be back soon!

class Student:
  def __init__(self, name, year): = name
    self.year = year
    self.grades = []
    self.attendance = {}
  def add_grade(self, grade):
    if type(grade) == Grade:
    return grade
  def get_avg(self):
    total_grades = 0
    minimum_passing = 65
    for score in self.grades:
     total_grades += score
     average = total_grades/len(self.grades)
    if average >= minimum_passing:
      return "My grade average is: {:1f}\nI am passing! :)".format(average)
      return "My grade average is: {:1f}\nI am failing! :(".format(average)

  def add_attendance(self, date, record):
    self.attendance[date] = record
def get_attendance(self):
    attendance = []
    for x in self.attendance.values():  
    for x in attendance:
      if sum(attendance) == len(self.attendance):
        return "I have perfect attendance!"
        return "I have {} absence/s recorded.".format(attendance.count(0))
  def __repr__(self):
    return "My name is {} and I am in year {}.\nThese are my grades: {}\n{}\nAttendance Record: {}\n{}\n".format(, self.year, self.grades, self.get_avg(), self.attendance, self.get_attendance())

class Grade:
  minimum_passing = 65
  def __init__(self, score):
    self.score = score

  def passing_score(grade):
    minimum_passing = 65
    if grade >= minimum_passing:
      return "This is a passing score!"
      return "You are failing!"
roger = Student("Roger van der Weyden", 10)
sandro = Student("Sandro Botticelli", 12)    
pieter = Student("Pieter Bruegel the Elder", 8)


sandro_grades = [90, 80, 95, 75, 65, 50, 45, 40, 35]
roger_grades = [95, 66, 78, 89, 98]

for x in sandro_grades:

for x in roger_grades:

pieter_attendance = [('2/6/2021', True), ('2/5/2021', False), ('2/7/2021', True)]
sandro_attendance = [('2/6/2021', True), ('2/5/2021', True), ('2/7/2021', True)]
roger_attendance = [('2/6/2021', False), ('2/5/2021', False), ('2/7/2021', True)]

for x in list(pieter_attendance):
    date = x[0]
    record = x[1]
    pieter.add_attendance(date, record)

for x in list(sandro_attendance):
    date = x[0]
    record = x[1]
    sandro.add_attendance(date, record)

for x in list(roger_attendance):
    date = x[0]
    record = x[1]
    roger.add_attendance(date, record)  
1 Like