将int改为float

This commit is contained in:
MX
2026-10-04 15:01:40 +08:00
parent 7eda1d2fc5
commit c623fd1ff3
+2 -2
View File
@@ -14,8 +14,8 @@ class Square(Shape):
def area(self): def area(self):
return self.side * self.side return self.side * self.side
r = int(input("请输入圆的半径: ")) r = float(input("请输入圆的半径: "))
side = int(input("请输入正方形的边长: ")) side = float(input("请输入正方形的边长: "))
shapes = [Circle(r), Square(side)] shapes = [Circle(r), Square(side)]
for i in shapes: for i in shapes:
print(i.__class__.__name__ + "的面积为: " + str(i.area())) print(i.__class__.__name__ + "的面积为: " + str(i.area()))