Rectangle Class
Completed
Create Rectangle(w, h) with methods area(), perimeter() and is_square(). Read the size and print the three results.
Input
One line: w h.
Output
Three lines.
Example
Input
3 4
Output
12 14 False
Editor
Python
Hints
Each method uses self.w and self.h.
Solution explanation
Methods let you ask an object questions about itself.
Show solution
class Rectangle:
def __init__(self, w, h):
self.w = w
self.h = h
def area(self):
return self.w * self.h
def perimeter(self):
return 2 * (self.w + self.h)
def is_square(self):
return self.w == self.h
r = Rectangle(*map(int, input().split()))
print(r.area())
print(r.perimeter())
print(r.is_square())