MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / DictGrade

Class DictGrade

example_code/item_060.py:178–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176
177print("Example 13")
178class DictGrade:
179 def __init__(self):
180 self._values = {}
181
182 def __get__(self, instance, instance_type):
183 if instance is None:
184 return self
185 return self._values.get(instance, 0)
186
187 def __set__(self, instance, value):
188 if not (0 <= value <= 100):
189 raise ValueError("Grade must be between 0 and 100")
190 self._values[instance] = value
191
192class DictExam:
193 math_grade = DictGrade()

Callers 1

DictExamClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected