First time working with classes in python, I'm am trying to define a function that will calculate the average of 2 grades, a midterm and final exam and return the letter grade using a try and exception block. I'm very sure the issue is in the get_grade function, just looking for some guidance.
I included the entire class definition portion of my program
class StudentClass(object):
def __init__(self, sid, name, midterm, final):
self.id = sid
self.name = name
self.mid = midterm
self.final = final
def get_grade(self):
try:
average = (self.midterm + self.final) /2
if average>=90:
return "A"
elif average>=80 and average <90:
return "B"
elif average>=70 and average <80:
return "C"
elif average>=60 and average <70:
return "D"
else:
return "F"
except:
print("error")
def getStudentData(self):
gradeletter = self.get_grade()
return "%-4s %-15s %5d %5d %7.1f" % (self.id, self.name, self.mid, self.final, gradeletter)