hnc-eduard/HNS/Excercises/13082023 ДЗ по фигурам JSON/shape.py

29 lines
692 B
Python

from abc import abstractmethod
from abc import ABC
class Shape(ABC):
color = ''
@abstractmethod
def area(self):
pass
@abstractmethod
def perimetr(self):
pass
@staticmethod
def create_shape(json):
if "type" in json:
shape_type = json["type"]
if shape_type == "circle":
return Circle(json("radius"))
elif shape_type == "square":
return Square(json("side"))
elif shape_type == "rectangle":
return Rectangle(json["width"], json["height"])
else:
raise TypeError(f'Неизвестная фигура {shape_type}')