Rectangle does not have attributes newsquare. please fix the code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Rectangle does not have attributes newsquare. please fix the code

class Rectangle: def __init__(self, width, height): self.width = width self.height = height def calculate_area(self): return self.width * self.height @classmethod def new_square (cls, side_length): return cls(side_length, side_length) square = Rectangle.newSquare(5) print(square.calculate_area())

24th Mar 2021, 9:30 AM
Bien Ibiso Michael
Bien Ibiso Michael - avatar
2 Answers
+ 4
You should recheck your code before asking us to correct it . Ok , what is newSquare in "Rectangle.newSquare(5)" ?? Shudn't it be Rectangle.new_square(5)
24th Mar 2021, 9:39 AM
Abhay
Abhay - avatar
+ 3
naw, just change the second to last line. should be: square = Rectangle.new_square(5)
24th Mar 2021, 9:43 AM
Slick
Slick - avatar