用python怎麼用類的方法計算圓柱的表面積和體積

時間 2021-06-18 04:10:12

1樓:墨汁諾

12345678910111213import mathclass cylinder():

def __init__(self,r,h):

self._r=r

self._h=h    def volume(self):

return math.pi*self._r*self._r*self._h

def area(self):

return 2*math.pi*(self._r*self.

_r+self._r*self._h)r=float(input("請輸入圓柱的底面半徑"))h=float(input("請輸入圓柱的高"))

c=cylinder(r,h)print("圓柱的表面積是:%.1f\n 圓柱的體積是:%.1f"%(c.area(),c.volume()))

例如:#! usr/bin/python

class cube:

def __init__(self,l,w,h):

self.l = l

self.w = w

self.h = h

def su***ce(self):

result = (l*w+w*h+h*l)*2

print 'the su***ce 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.su***ce()

a.volume()

2樓:薔雯利

大圓錐體積減小圓錐體積,表面積是大圓錐表面積減小圓錐表面積,再加上小圓面積,給小學生答題真不容易

寫用簡便方法計算的算式,寫6個用簡便方法計算的算式

518姚峰峰 212 198 200 12 100 98 200 12 100 98 12 98 100 200 110 100 200 410 13.75 3.75 6.48 13.75 3.75 6.48 10 6.48 3.52 0.75 42.7 57.3 0.573 25 3 7972 0...

72 520十280x52用簡便方法怎麼計算

義明智 簡便計算 72 520 十280x52 72x520 28x520 72 28 x520 100x520 52000 火星 方法1 72x520 280x52 720x52 280x52 720 280 x52 1000x52 52000 方法2 72x520 280x52 72x520 2...

腕式電子血壓計怎麼用使用方法怎樣

本身電子血壓計就不是很很準確的,相比之下臂式也要比腕式的強一些,最好是不要買這種的,雖然確實是方便,我家用的是由泰血壓計,屬於自動的水銀血壓計,準確不說,用起來也相當的方便,上買的,你可以去了解一下,是現在最新型的血壓計了 http shop110481737.如何使用歐姆龍電子血壓計 亞洲器械城 ...