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 | Introduction to Python OOP
Object-Oriented Programming in Python
Sectionย 1. Chapterย 5
single

single

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

Ask AI

expand

Ask AI

ChatGPT

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

some-alt