举报
cendon
这个是计算长方体的,别的也一样,具体想做高级一点的什么自己拓展吧,很简单 #! usr/bin/python class Cube: def __init__(self,l,w,h): self.l = l self.w = w self.h = h def surface(self): result = (l*w+w*h+h*l)*2 print 'the surface of cube is '+str(result) return result def volume(self): result = l*w*h print 'the volume of cube is '+str(result) return result l = 2 w = 3 h = 4 a = Cube(l,w,h) a.surface() a.volume()