使用for循环逐个调用area并且输出面积

This commit is contained in:
MX
2026-10-04 14:54:08 +08:00
parent 91420025c0
commit 7eda1d2fc5
+2
View File
@@ -17,3 +17,5 @@ class Square(Shape):
r = int(input("请输入圆的半径: "))
side = int(input("请输入正方形的边长: "))
shapes = [Circle(r), Square(side)]
for i in shapes:
print(i.__class__.__name__ + "的面积为: " + str(i.area()))