Python 3.7+. Any better way to write this code? This is a method from my Student class:
# method to calculate GPA
def gpa(self):
try:
return self.qpoints/self.credits
except ZeroDivisionError :
return 0
I'd rather not use try/except, and I would also rather not use ZeroDivisionError. Is there a better way to write this? Maybe an if/else statement?
# method to calculate GPA
def gpa(self):
if self.credits==0:
return 0
else:
return self.qpoints/self.credits
Python 3.7+. Any better way to write this code? This is a method from my Student...