Tell us what’s happening:
Describe your issue in detail here.
Basically I am trying to understand what the below line in the project rubric is asking of me. Please if someone could just break it down:
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.
Your code so far
class Rectangle:
name = 'Rectangle'
def __init__(self, width, height):
self.width = width
self.height = height
def __str__(self):
return f"{self.name}(width={self.width}, height={self.height})"
def set_width(self, width) -> int:
self.width = width
return self.width
def set_height(self, height) -> int:
self.height = height
return self.height
def get_area(self) -> int:
return self.width * self.height
def get_perimeter(self) -> int:
return (2 * self.set_width(self.width)) + (2 * self.set_height(self.height))
def get_diagonal(self) -> int:
return ((self.set_width(self.width) ** 2) + (self.set_height(self.height) ** 2)) ** .5
def get_picture(self) -> str:
display = ''
if self.width > 50 or self.height > 50:
return "Too big for picture."
for i in range(0, self.height):
display += '*' * self.width
display += '\n'
return display
def get_amount_inside(self, shape):
# Get the Greatest Common Denominator (GCD)
odd = []
even = []
width = self.width
height = self.height
if width % 2 == 0:
for i in range(1, width + 1):
if width % i == 0:
even.append(i)
else:
for j in range(1, width + 1):
if width % j == 0:
odd.append(j)
if height % 2 == 0:
for i in range(1, height + 1):
if height % i == 0:
even.append(i)
else:
for j in range(1, height + 1):
if height % j != 0:
odd.append(j)
# Union of both list
# and finding the common factors bw them
union = list(set(odd) & set(even))
greatest = max(union)
return greatest
# if shape is self:
# return 'rectangle'
# return "square"
class Square(Rectangle):
name = 'Square'
def __init__(self, side_length):
self.side_length = side_length
super().__init__(width=side_length, height=side_length)
def __str__(self):
return f"{self.name}(side={self.side_length})"
def set_side(self, side) -> int:
self.side_length = side
return self.side_length
def set_height(self, height) -> int:
return self.set_side(height)
def set_width(self, width) -> int:
return self.set_side(width)
def get_picture(self) -> str:
display = ''
if self.side_length > 50:
return "Too big for picture."
for i in range(0, self.side_length):
display += '*' * self.side_length
display += '\n'
return display
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Challenge: Polygon Area Calculator
Link to the challenge: