Question: 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:
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?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
