-
Notifications
You must be signed in to change notification settings - Fork 22
/
Solution.py
37 lines (30 loc) · 844 Bytes
/
Solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from math import pi
class Rectangle:
def __init__(self,l,w):
self.l = l
self.w = w
def area(self):
return (self.l*self.w)
class Circle:
def __init__(self,r):
self.r = r
def area(self):
return (pi*self.r*self.r)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input())
queries = []
for _ in range(q):
args = input().split(' ')
shape_name, params = args[0], map(int, args[1:])
if shape_name == "rectangle":
a, b = params[0], params[1]
shape = Rectangle(a, b)
elif shape_name == "circle":
r = params[0]
shape = Circle(r)
else:
raise ValueError("invalid shape type")
fptr.write("%.2f\n" % shape.area())
fptr.close()