24 lines
423 B
Python
24 lines
423 B
Python
|
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
|
||
|
|