用python 写一组类(class) 对应各种几何体(正方体,长方体,球,圆柱)的表面积和体积的编码

披头散发777 1年前 已收到2个回答 举报

cendon 幼苗

共回答了15个问题采纳率:93.3% 举报

class Cube:
def __init__(self,):
self.type = xxx
self.surface = xxx
不知道你要干啥,计算还是定义

1年前 追问

9

披头散发777 举报

分别计算正方体长方体,球,圆柱的表面积和体积

举报 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()

董建 幼苗

共回答了15个问题采纳率:73.3% 举报

而表现

1年前

2
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 19 q. 0.586 s. - webmaster@yulucn.com