43 lines
671 B
Python
43 lines
671 B
Python
|
import json
|
||
|
import math
|
||
|
|
||
|
|
||
|
class Shape:
|
||
|
def aria(self):
|
||
|
return -1
|
||
|
|
||
|
def perimeter(self):
|
||
|
return -2
|
||
|
|
||
|
|
||
|
class Rectangle(Shape):
|
||
|
def __init__(self, w, h):
|
||
|
self.w = w
|
||
|
self.h = h
|
||
|
|
||
|
def perimeter(self):
|
||
|
return 2 * (self.w + self.h)
|
||
|
|
||
|
|
||
|
class Circle(Shape):
|
||
|
def __init__(self, radius):
|
||
|
self.radius = radius
|
||
|
|
||
|
def aria(self):
|
||
|
return math.pi + (self.radius ** 2)
|
||
|
|
||
|
|
||
|
class Square(Shape):
|
||
|
def __init__(self, a):
|
||
|
self.a = a
|
||
|
|
||
|
def perimeter(self):
|
||
|
return 4 * self.a
|
||
|
|
||
|
|
||
|
def json_to_python():
|
||
|
while open('shapes.json') as shapes:
|
||
|
data = json.loads(shapes)
|
||
|
return data
|
||
|
|