题解 | #图形面积#
图形面积
http://www.nowcoder.com/practice/cef4036a7bf745d0aeb93e305ba6ead4
比较复杂
import math, cmath
pi = math.pi
class Square(object):
def __init__(self, line):
self.line = line
def Calculated_area(self):
print(self.line * self.line)
class Rectangle(Square):
def Calculated_area(self):
x = self.line.split(" ")
print(int(x[0])*int(x[1]))
class Circular(Square):
def Calculated_area(self):
print("%.3f" % (pi * self.line * self.line))
class Triange(Square):
def Calculated_area(self):
p = (self.line*3)/2
s = (p*(p-self.line)*(p-self.line)*(p-self.line)) ** 0.5
print("%.3f" % s)
a = input()
if a == "Square":
S = Square(int(input()))
S.Calculated_area()
elif a == "Rectangle":
S = Rectangle(input())
S.Calculated_area()
elif a == "Circular":
S = Circular(int(input()))
S.Calculated_area()
elif a == "Triangle":
S = Triange(int(input()))
S.Calculated_area()