Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started