独学プログラマーの課題のプログラムを書き写してみましたが、修正箇所がわかりません。
課題RectangleとSquareクラスを作ろう。両方のクラスに、その図形の外周の長さを計算して返す
calculate_perimeterメソッドを定義しよう。そして、RectangleとSquareのオブジェクトを作って、
それぞれのcalcucate_perimeterメソッドを呼ぼう。
python3.7.3
コード
class
1 def __init__(self, width, length): 2 self.width = width 3 self.length = length 4 def calcurate_perimeter(self): 5 return self.width * 2 + self.length * 2 6 class Square(): 7 def __init__(self, sl): 8 self.sl = sl 9 def calculate_perimeter(self): 10 return self.sl * 4 11 a_rectangle = Rectangle(25, 50) 12 a_square = Square(20) 13 print(a_rectangle.calculate_perimeter()) 14 15Traceback (most recent call last): 16 File "<pyshell#34>", line 1, in <module> 17 print(a_rectangle.calculate_perimeter()) 18AttributeError: 'Rectangle' object has no attribute 'calculate_perimeter'
このままではコード6が見づらいので、質門を編集し、<code>ボタンで、出てくる’’’の枠の中にコードを貼り付けてください
また、エラーメッセージが出るなら、それをそのまま提示してください
回答2件
あなたの回答
tips
プレビュー