0
class Bola:
def __init__(self, cor, circunferencia, material):
self.__cor = cor
self.__circunferencia = circunferencia
self.__material = material
@cor.setter
def cor(self, cor):
self.__cor = cor
@property
def mostraCor(self):
return self.__cor
Guys, I’m doing this exercise on Jupyter Notebook, but it’s making the following mistake:
NameError Traceback (most recent call last)
<ipython-input-12-c66d63af7d4c> in <module>
----> 1 class Bola:
2
3 def __init__(self, cor, circunferencia, material):
4 self.__cor = cor
5 self.__circunferencia = circunferencia
<ipython-input-12-c66d63af7d4c> in Bola()
6 self.__material = material
7
----> 8 @cor.setter
9 def cor(self, cor):
10 self.__cor = cor
NameError: name 'cor' is not defined
Could someone help me? The problem is in Setter, but I don’t know how to fix it.
Actually the problem is getter, you created a property called
mostraCor
, when it should just becor
: https://ideone.com/LG7cBs - in the question suggested above as duplicate, there are other recommendations also on creating getters and setters– hkotsubo