Tell us what’s happening:
Failed:
12. Rectangle(3, 6).get_diagonal() should return 6.708203932499369.
Failed:
13. Square(5).get_diagonal() should return 7.0710678118654755.
Passed:
In my Spyder-ide I get the correct outputs:
runfile(‘/home/jajarvin/.config/spyder-py3/jj/Build_a_Polygon_Area_ Calculator_jj.py’, wdir=‘/home/jajarvin/.config/spyder-py3/jj’)
Rectangle(3, 6).get_diagonal() ==> 6.708203932499369
-----------------
Square(5).get_diagonal() ==> 7.0710678118654755
------------------
Your code so far
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def set_width(self, width):
self.width = width
def set_height(self, height):
self.height = height
def get_area(self):
return self.width * self.height
def get_perimeter(self):
return 2 * (self.width + self.height)
def get_diagonal(self):
#return sqrt(self.width * self.width + self.height * self.height)
#return sqrt(pow(self.width, 2) + pow(self.height, 2))
return sqrt(self.width ** 2 + self.height ** 2)
def get_picture(self):
if self.width > 50 or self.height > 50:
return "Too big for picture."
else:
shape_str = ""
for row in range(self.height):
for col in range(self.width):
shape_str += "*"
shape_str += "\n"
return shape_str
def get_amount_inside(self, shape):
self.shape = shape
if self.shape.width <= self.width and self.shape.height <= self.height:
if isinstance(self.shape, Square):
x = self.width // self.shape.height
# print(f"x - {x}")
y = self.height // self.shape.height
# print(f"y - {y}")
return x * y
else:
x = self.width // self.shape.width
y = self.height // self.shape.height
# print(f"y - {y}")
lkm = min(x,y)
return lkm
else:
return 0
def __str__(self):
return f"Rectangle(width={self.width}, height={self.height})"
#-------------------------------------------------------
class Square(Rectangle):
def __init__(self, side_length):
self.width = side_length
self.height = side_length
def set_width(self, width):
self.width = width
self.width = width
def set_height(self, height):
self.height = height
self.width = height
def set_side(self, side):
self.width = side
self.height = side
def __str__(self):
return f"Square(side={self.width})"
def __str__(self):
return f"Square(side={self.width})"
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Challenge Information:
Build a Polygon Area Calculator - Build a Polygon Area Calculator