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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!