Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions