题解 | #图形面积#
图形面积
https://www.nowcoder.com/practice/cef4036a7bf745d0aeb93e305ba6ead4
import math class Square(object): def area(line): s = line * line print(s) class Rectangle(Square): def area(l, d): s = l * d print(s) class Circular(Square): def area(r): s = math.pi * r * r print('{:.3f}'.format(s)) class Triangle(Square): def area(a): s = math.sqrt(3) * a * a / 4 print('{:.3f}'.format(s)) pattern = input() num = input() if pattern == 'Square': Square.area(int(num)) elif pattern == 'Circular': Circular.area(int(num)) elif pattern == 'Triangle': Triangle.area(int(num)) else: num = num.split(' ') Rectangle.area(int(num[0]), int(num[1]))