导入math包

import math

创建父类Square

class Square:
    def __init__(self, edge):
        self.edge = edge

    def area(self):
        return self.edge ** 2

创建子类Rectangle、Circular、Triangle

class Rectangle(Square):
    def r_area(self):
        lenght = self.edge.split(' ')
        return int(lenght[0]) * int(lenght[1])


class Circular(Square):
    def c_area(self):
        return math.pi * self.edge ** 2


class Triangle(Square):
    def t_area(self):
        return math.sqrt(3) * (self.edge ** 2) / 4

进行分类判断与面积计算

graph_type = input()
num = input()
if graph_type == 'Square':
    print(Square(int(num)).area())
elif graph_type == 'Rectangle':
    print(Rectangle(num).r_area())
elif graph_type == 'Circular':
    print('%.3f' % Circular(int(num)).c_area())
elif graph_type == 'Triangle':
    print('%.3f' % Triangle(int(num)).t_area())