0

How can I use the input?

okay so I tried to change this 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.new_square(5) print(square.calculate_area()) to this 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.new_square(input('')) print(square.calculate_area()) so that the area of a square with the length of a user input can be calculated. but I don't know what I need to change that it work because I get a type error no matter what I try. thanks for your help

8th Jun 2018, 1:54 PM
Em0125
Em0125 - avatar
1 ответ
0
square = Rectangle.new_square(float(input(""))) essential input value which is string needs to be converted into number like int or float or double
8th Jun 2018, 6:11 PM
Vineet Bharadwaj
Vineet Bharadwaj - avatar