From 9ef3af452351612aaf8118da091d32b5ebf31b40 Mon Sep 17 00:00:00 2001 From: azzzz <2431294433@qq.com> Date: Mon, 5 Oct 2026 18:42:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=B8=BB=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 7619f6c..bf964f5 100644 --- a/main.py +++ b/main.py @@ -2,12 +2,22 @@ class Shape: def area(self): return 0 class Circle(Shape): - def __init__(self,r): + def __init__(self,name,r): + self.name = name self.r = r def area(self): return (3.14*self.r*self.r) class Square(Shape): - def __init__(self,side): + def __init__(self,name,side): + self.name = name self.side = side def area(self): return (self.side*self.side) + +shape_list = [] +circle_1 = Circle("circle_1",1) +square_1 = Square("square_1",1) +shape_list.append(circle_1) +shape_list.append(square_1) +for shape in shape_list: + print(f"{shape.name}的面积:{shape.area()}") \ No newline at end of file