Add a Method to Rectangle
Beginner · Write the code · from Python Classes and Objects: OOP from the Ground Up
From the lesson: Python Classes and Objects: OOP from the Ground Up
Imagine you own a bakery and you have a cookie cutter shaped like a star. Every time you press it into dough, you get a new star-shaped cookie. The cutter itself isn't a cookie - it's a blueprint for making cookies.
Read the lessonCreate a Rectangle class with width and height attributes. Add an area() method that returns the area (width times height). Create a rectangle with width 5 and height 3, then print the result of calling area().
# Create your Rectangle class here
More Classes and Objects exercises
- Create a Book ClassBeginner
- Predict the Counter OutputBeginner
- Fix the Student ClassIntermediate
- Add __str__ to a ProductIntermediate
- Build a Player Class with Score TrackingIntermediate
- Refactor Functions into a ClassAdvanced
All Python exercises · 50 practice problems · Object-Oriented Programming quiz