为什么错了?
class Student(object):
def __init__(self,name,score):
self.name=name
self.__score=score
@property
def score(self):
return self.__score
@score.setter
def score(self,score):
if score<0 or score>100:
raise ValueError('invalid score')
self.__score = score
@property
def grade(self):
if score>=80:
grade=A
elif score>=60:
grade=B
else:
grade=C
>>> s = Student('Bob',69)
>>> print s.grade
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
print s.grade
File "<pyshell#5>", line 15, in grade
if score>=80:
NameError: global name 'score' is not defined