1
class Linha(object):
def __init__(self, x, y):
self.x = x
self.y = y
@property
def x(self):
return self._x
@x.setter
def x(self, valor):
valor = int(valor)
if valor >= 0:
self._x = valor
else:
raise ValueError('Valor de x inválido !')
@property
def y(self):
return self._x
@y.setter
def y(self, valor):
valor = int(valor)
if valor >= 0:
self._y = valor
else:
raise ValueError('Valor de y inválido !')
def __str__(self):
return '(%i - %i)' %(self.x, self.y)
def main():
while True:
try:
x = input('X :')
y = input('Y :')
linha = Linha(x, y)
print(linha)
except ValueError as erro:
print(erro)
if __name__ == '__main__':
main()
When I try to create an object for example:
line = Row (2, 8)
It creates a line object with values x = 2 and y = 2.
Where is the error ???
That’s right, I didn’t even see that mistake on the property.
– ThiagoO
@Thiagothiaguinho: Don’t forget to accept the answer.
– jsbueno