hnc-daniil/HNC/Exercises/JSON/Shape.py

24 lines
423 B
Python
Raw Permalink Normal View History

2023-11-06 15:35:22 +01:00
import math
from abc import abstractmethod
class Shape:
color = ''
@abstractmethod
def area(self):
pass
@abstractmethod
def perimeter(self):
pass
@staticmethod
def convert_to_json(obj):
if isinstance(obj, Shape):
result = obj.__dict__
result['type'] = obj.__class__.__name__
result['color'] = obj.color
return result