Python __ 面向对象基础
import math as m
class Rect:
l = 0.0
h = 0.0
z = 0.0
def __init__(self, l, h, z):
self.l = l
self.h = h
self.z = z
def length(self):
return (self.l + self.h) * 2
def area(self):
return self.l * self.h
# 立方体类Cubic
class Cubic(Rect):
def __init__(self, l, h, z):
super().__init__(l, h, z)
def area(self):
return (self.h * self.l + self.l * self.z + self.h * self.z) * 2
def v(self):
return self.h * self.l * self.z
# 四棱锥类Pyramid
class Pyramid(Rect):
def __init__(self, l, h, z):
super().__init__(l, h, z)
def area(self):
return m.sqrt(self.h*self.h+4*self.z*self.z)*self.l/2+self.h*self.l+m.sqrt(self.l*self.l+4*self.z*self.z)*self.h/2
def v(self):
return self.h * self.l * self.z/3
while True:
try:
a, b, c = map(float, input().split())
C = Cubic(a, b, c)
P = Pyramid(a, b, c)
if a<=0 or b<=0 or c<=0:
print("0.00 0.00 0.00 0.00")
else:
# print(C.area, C.v, P.area, P.v)
print("{:.2f} {:.2f} {:.2f} {:.2f}".format(C.area(), C.v(), P.area(), P.v()))
except:
break