Attributes Python Adding a Set value -
for essay class need attribute stores grade should public , betweem 0.0 , 4.0. thinking set_grade(self,grade) how implement if statement make sure return number 0.0 between 4.0
class assessment: grade = 0 def get_grade(self): return self.grade """this operation creating concrete subclass of assessment""" class essay (assessment): """this operation getting grade grade essay class return grade""" def get_grade(self): return self.grade """this operation creating teamproject class individual score , team score grade""" class teamproject(assessment): ind_sc = 0 ts_sc = 0 """this operation getting grade individual score , team score , returning average""" def get_grade(self): return (self.ind_sc +self.ts_sc) / 2
how implement if statement make sure return number 0.0 between 4.0
try this:
def set_grade(self, grade): if grade < 0.0 or grade > 4.0: raise valueerror('out of range') self.grade = grade
if use in assessent , essay, teamscore in-bounds.
hope helps :-)
Comments
Post a Comment