The code is just for a lesson where I’m pretty much just copying the code that the teacher is writing. This lesson is about classes and objects, and I’m having issue with my Square object.
class Square:
def __init__(self, height="0", width="0"):
self.height = height
self.width = width
#Now we are going to make a 'getter' function (Retreives a value)
@property
def height(self):
print("Retrieving the height")
return self.__height
#Now we are going to make a setter function
@height.setter
def height(self, value):
if value.isdigit():
self.__height = value
else:
print("Please only enter numbers for height.")
@property
def width(self):
print("Retrieving the width")
return self.__width
@width.setter
def width(self, value):
if value.isdigit():
self.width = value
else:
print("Please only enter numbers for width.")
def get_area(self):
return int(self.__width) * int(self.height)
For some reason, even though the code is the same for the height, and width properties, except for being called height vs width, I keep getting errors on the width getter function.
I tried searching the error, but since this isn’t anything recursive, I couldn’t find anything helpful. Any help is much appreciated!!
I tried to define a width property, and I expected it to have no problems, like the height property I defined before.
Will is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.