kakil / rectangle

OOP Rectangle class

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create Rectangle Class

Project Brief - Part 1

Today we will practice object-oriented programming. Imagine you are developing a civil engineering application (e.g., AutoCAD) with Python. Your current task is to create a Python class that represents a rectangle geometrical figure. The Rectangle class should:

Two instance attributes, width, and height. An area() method that returns the area of the rectangle. A perimeter() method that returns the perimeter of the rectangle. An is_square() method that returns True if the rectangle is a square and False (or None) if it is not.

Expected Output - Part 1

Your task is to simply define the class. You don’t need to call the class.

Project Brief - Part 2

Yesterday, we coded a Rectangle class that had a width and a height attribute. The class also had an area(), perimeter(), and an is_square() method.

Your task for today is to add two magic methods to that class str and eq. The str method should return a string representation of the Rectangle and eq should enable comparing two different rectangle instances returning True or False based on whether the rectangles are similar or not (i.e., have the same width and height).

Expected Output - Part 2

Your task is to simply define the class. You don’t need to call the class.

About

OOP Rectangle class


Languages

Language:Python 100.0%