class Circle:
def __init__(self,radius):
self.__radius=radius
def getRadius(self):
return self.__radius
def setRadius(self,r):
self.__radius=r
def area(self):
return 3.14*self.__radius**2
def cir(self):
return 2*3.14*self.__radius
def __str__(self):
return '半径是:'+str(self.__radius)
class Rectangle:
def __init__(self,length,width):
self.__length=length
self.__width=width
def getLength(self):
return self.__length
def getWidth(self):
return self.__width
def setLength(self,length):
self.__length=length
def setWidth(self,width):
self.__width=width
def area(self):
return self.__length*self.__width
def cir(self):
return 2*(self.__length+self.__width)
def __str__(self):
return ' 长是:'+str(self.__length) +' 宽是:'+str(self.__width)
class Ball(Circle):
def __init__(self,radius):
Circle.__init__(self, radius)
def area(self):
return 4*3.14*self.getRadius()**2
def volume(self):
return 4/3*3.14*self.getRadius()**3
def __str__(self):
return Circle.__str__(self)
class Cuboid(Rectangle):
def __init__(self,length,width,height):
super().__init__(length,width)
self.__height=height
def getHeight(self):
return self.__height
def setHeight(self,height):
self.__height=height
def area(self):
return 2*(self.getWidth()*self.getLength()+\
self.getLength()*self.__height\
+self.getWidth()*self.__height)
def volume(self):
return self.getWidth()*self.getLength()*self.__height
def __str__(self):
return super().__str__()+' 高是:'+str(self.__height)
class Copperplate(Circle,Rectangle):
def __init__(self,radius,length,width):
super().__init__(radius)
Rectangle.__init__(self, length, width)
def area(self):
return Circle.area(self)-Rectangle.area(self)
def __str__(self):
return Circle.__str__(self)+Rectangle.__str__(self)
c=Circle(5)
print("半径为{0}的圆的面积是{1},周长是{2:.2f}".\
format(c.getRadius(),c.area(),c.cir()))
c.setRadius(9)
print("半径为{0}的圆的面积是{1},周长是{2:.2f}".\
format(c.getRadius(),c.area(),c.cir()))
r=Rectangle(4,5)
print("长为{0},宽为{1}的矩形的面积是{2},周长是{3}".\
format(r.getLength(),r.getWidth(),r.area(),r.cir()))
r.setLength(7)
r.setWidth(8)
print("长为{0},宽为{1}的矩形的面积是{2},周长是{3}".\
format(r.getLength(),r.getWidth(),r.area(),r.cir()))
b=Ball(5)
print("半径为{0}的球的表面积面积是{1:.2f},体积是{2:.2f}".\
format(b.getRadius(),b.area(),b.volume()))
b.setRadius(9)
print("半径为{0}的球的表面积面积是{1:.2f},体积是{2:.2f}".\
format(b.getRadius(),b.area(),b.volume()))
y=Cuboid(3,4,5)
print("长为{0},宽为{1},高为{2}的长方体的表面积是{3},体积是{4}".\
format(y.getLength(),y.getWidth(),y.getHeight(),\
y.area(),y.volume()))
y.setLength(7)
y.setWidth(8)
y.setHeight(9)
print("长为{0},宽为{1},高为{2}的长方体的表面积是{3},体积是{4}".\
format(y.getLength(),y.getWidth(),y.getHeight(),\
y.area(),y.volume()))
p=Copperplate(9,2,3)
print("半径为{0},长为{1},宽为{2}的铜钱的面积是{3:.2f}".\
format(p.getRadius(),p.getLength(),p.getWidth(),p.area()))
p.setRadius(7)
p.setLength(3)
p.setWidth(4)
print("半径为{0},长为{1},宽为{2}的铜钱的面积是{3:.2f}".\
format(p.getRadius(),p.getLength(),p.getWidth(),p.area()))
print(c)
print(r)
print(b)
print(y)
print(p)
改好了,你这个空行让人头疼