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

31 lines
674 B
Python
Raw Normal View History

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 json["radius"]
elif shape_type == "square":
return json["side"]
elif shape_type == "rectangle":
return json["width"], json["height"]
else:
raise TypeError(f'Неизвестная фигура {shape_type}')
print()