長方体の体積を求めるClassを作り、それを元に正方体の体積を、単位付きでアウトプットしたいと思っています。以下の通りコードを書いてみたのですが、エラーになってしまいます。アドバイスよろしくお願いいたします。
python
1#直方体の体積を求める 2class Cuboid: 3 def __init__(self,w,d,h): 4 self.w=w 5 self.d=d 6 self.h=h 7 8 def volume(self): 9 return self.w*self.d*self.h 10 11a=Cuboid(10,20,30) 12a.volume() 13#6000 14 15#メソッドをオーバーライドし、単位付きで、正方形の体積をアウトプットする 16 17class Cube(Cuboid): 18 def __init__(self,equalSides,unit='cm'): 19 self.w=self.d =self.h=equalSides 20 self.unit = unit 21 22 def unitVolume(self): 23 return str(self.volume)+self.unit 24b=Cube(10) 25b.unitVolume() 26 27# エラーコード 28'<bound method Cuboid.volume of <__main__.Cube object at 0x7fbab8b74e80>>cm' 29
回答1件
あなたの回答
tips
プレビュー