Files
----3/陈张本-26020007010-912523257.py
T
2026-10-07 22:18:59 +08:00

21 lines
527 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
class Shape:
def area(self):
return 0
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def area(self):
return math.pi * self.radius * self.radius
class Square(Shape):
def __init__(self, side):
self.side = side
def area(self):
return self.side * self.side
r=float(input("请输入半径r:"))
side=float(input("请输入边长side:"))
shapes=[Circle(r),Square(side)]
for i in shapes:
print(i.__class__.__name__,"面积为:",i.area())