赞
踩
python 版本
class Cuboid:
def __init__(self, length, width, high):
# data must > 0
if length <= 0:
raise ValueError("length <= 0!")
if width <= 0:
raise ValueError("width <= 0!")
if high <= 0:
raise ValueError("high <= 0!")
# save the data
self.__length = length
self.__width = width
self.__high = high
# caculate and save the surface area and volume
self.__area = float(2 * (self.__length * self.__width + self.__width * self.__high + self.__high * self.__length))
self.__volume = float(self.__length * self.__width * self.__high)
def get_area(self):
return self.__area
def get_volume(self):
return self.__volume
if __name__ == '__main__':
length = fl
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。