Challenge: Creating and Using Methods
Task
Swipe to start coding
Create a class that represents a rectangle and implements methods to calculate its area and perimeter.
- Define a class named
Rectangle. - Add an
__init__method that takeswidthandheightas arguments and stores them as instance variables. - Implement a method called
areathat returns the area of the rectangle. - Implement a method called
perimeterthat returns the perimeter of the rectangle.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 5
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.85
Challenge: Creating and Using Methods
Swipe to show menu
Task
Swipe to start coding
Create a class that represents a rectangle and implements methods to calculate its area and perimeter.
- Define a class named
Rectangle. - Add an
__init__method that takeswidthandheightas arguments and stores them as instance variables. - Implement a method called
areathat returns the area of the rectangle. - Implement a method called
perimeterthat returns the perimeter of the rectangle.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 5
single