54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
|
|
class Rectangle:
|
|
def __init__(self, width: float, height: float) -> None:
|
|
self.width = width
|
|
self.height = height
|
|
|
|
def __repr__(self) -> str:
|
|
return f"Rectangle(width={self.width}, height={self.height})"
|
|
|
|
def set_width(self, width: float) -> None:
|
|
self.width = width
|
|
|
|
def set_height(self, height: float) -> None:
|
|
self.height = height
|
|
|
|
def get_area(self) -> float:
|
|
return self.width*self.height
|
|
|
|
def get_perimeter(self) -> float:
|
|
return 2*self.width + 2*self.height
|
|
|
|
def get_diagonal(self) -> float:
|
|
return (self.width**2 + self.height**2)**.5
|
|
|
|
def get_picture(self) -> str:
|
|
if (self.width > 50 or self.height > 50):
|
|
return "Too big for picture."
|
|
return "\n".join(["*"*self.width for i in range(self.height)])+'\n'
|
|
|
|
def get_amount_inside(self, other: Rectangle) -> int:
|
|
return int(self.width/other.width)*int(self.height/other.height)
|
|
|
|
|
|
|
|
|
|
class Square(Rectangle):
|
|
def __init__(self, side: float) -> None:
|
|
super().__init__(side, side)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"Square(side={self.height})"
|
|
|
|
def set_side(self, side: float) -> None:
|
|
self.height = side
|
|
self.width = side
|
|
|
|
def set_height(self, side: float) -> None:
|
|
self.set_side(side)
|
|
|
|
def set_width(self, side: float) -> None:
|
|
self.set_side(side)
|