Hi all,
I’m working on the next project at FCC and got stuck on probably very basic error.
Error:
python main.py
True
True
Rectangle(width=3, height=10)
Traceback (most recent call last):
File “main.py”, line 12, in
sq = shape_calculator.Square(9)
File “/home/runner/boilerplate-polygon-area-calculator/shape_calculator.py”, line 74, in init
super().init(height , width)
NameError: name ‘height’ is not defined
exit status 1
My code is:
class Rectangle():
def __init__(self, width, height):
self.height = height
self.width = width
self.area = True
self.diagonal = True
self.perimeter = True
#set_width, set_height, get_area: Returns area (width * height)
def set_width(self, width):
self.width = width
def set_height(self,height):
self.height = height
def set_area(self, area):
self.area = self.width * self.height
def get_area(self):
return self.area
#get_perimeter: Returns perimeter (2 * width + 2 * height)
def set_perimeter(self, perimeter):
self.perimeter = 2 * width + 2 * height
def get_perimeter(self):
return self.perimeter
#get_diagonal: Returns diagonal ((width ** 2 + height ** 2) ** .5)
def set_diagonal(self, diagonal):
self.diagonal = (width ** 2 + height ** 2) ** .5
def get_diagonal(self):
return self.diagonal
#get_picture: Returns a string that represents the shape using lines of "*".
#The number of lines should be equal to the height width.
#There should be a new line (\n) at the end of each line.
#If the width or height is larger than 50,
#this should return the string: "Too big for picture.".
def set_picture(self, picture):
if self.width > 50 or self.height > 50:
print("Too big for picture.")
else:
#found on google python print pattern
for i in range(self.width):
for k in range(self.height):
print("*", end = " ")
print()
def get_picture(self):
return self.picture
#get_amount_inside: Takes another shape (square or rectangle) as an argument. Returns the number of times the passed in shape could fit inside the shape (with no rotations). For instance, a rectangle with a width of 4 and a height of 8 could fit in two squares with sides of 4.
def set_amount_inside():
pass
def get_amount_inside(self):
pass
#Additionally, if an instance of a Rectangle is represented
#as a string, it should look like:
#Rectangle(width=5, height=10)
def __str__(self):
return f'Rectangle(width={self.width}, height={self.height})'
#the Square class should be a subclass of Rectangle.
class Square(Rectangle):
def __init__(self, side):
super().__init__(height , width)
self.side = side
self.height = side
self.width = side
#also contain a set_side method.
def set_side(self, side):
self.height = side
self.width = side
def get_side(self):
return self.width or self.height
def __str__(self):
return f'Square(side={self.side})'
I tried to work around since yesterday but run out of options.