Rectangle Class
Easy
Create a class Rectangle with attributes width and height, set in __init__. Add methods area() returning width*height, and perimeter() returning 2*(width+height).
Input
Two numbers: width and height.
Output
The area and perimeter as numbers.
Example
Input
Rectangle(4, 5)
Output
Area: 20 Perimeter: 18
Store width and height as self.width and self.height in __init__, then define area() and perimeter() methods using them.
10 XP on solve
Back to lesson
Your Solution
Output
Click "Run" to execute your code...
⏳ Loading Python runtime (first run may take a few seconds)...
Log in to submit your solution and earn XP.