Tell us what’s happening:
- Rectangle(4,8).get_amount_inside(Rectangle(3, 6)) should return 1.
I can’t pass this test.
Please help me.
Your code so far
import math
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 math.sqrt(self.width **2 + self.height ** 2)
def get_picture(self):
if self.width > 50 or self.height > 50:
return "Too big for picture."
return ("*" * self.width + "\n") * self.height
def get_amount_inside(self, other):
return (self.width / other.width) * (self.height / other.height)
def __str__(self):
return f"Rectangle(width={self.width}, height={self.height})"
class Square(Rectangle):
def __init__(self, side):
super().__init__(side, side)
self.side = side
def set_width(self, width):
self.width = width
self.height = width
self.side = width
def set_height(self, height):
self.width = height
self.height = height
self.side = height
def set_side(self, side):
self.width = side
self.height = side
self.side = side
def __str__(self):
return f"Square(side={self.side})"
rect = Rectangle(10, 5)
print(rect.get_area())
rect.set_height(3)
print(rect.get_perimeter())
print(rect)
print(rect.get_picture())
sq = Square(9)
print(sq.get_area())
sq.set_side(4)
print(sq.get_diagonal())
print(sq)
print(sq.get_picture())
rect.set_height(8)
rect.set_width(16)
print(rect.get_amount_inside(sq))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Build a Polygon Area Calculator - Build a Polygon Area Calculator