Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Creating and Using Methods | Section
Object-Oriented Programming in Python

bookChallenge: 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 takes width and height as arguments and stores them as instance variables.
  • Implement a method called area that returns the area of the rectangle.
  • Implement a method called perimeter that returns the perimeter of the rectangle.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 5
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: 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 takes width and height as arguments and stores them as instance variables.
  • Implement a method called area that returns the area of the rectangle.
  • Implement a method called perimeter that returns the perimeter of the rectangle.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 5
single

single

some-alt