Challenge 3: Implement Area and Perimeter Member Methods

Solve an exercise to practice your Python classes, especially the member methods inside a class.

Problem Statement

Implement the area() and perimeter() methods to return the area and perimeter of the rectangle respectively, where

Area=widthheightArea = width*height

Perimeter=2width+2heightPerimeter = 2*width + 2*height

Input

A class Rectangle with constructor having the rectangle coordinates x1, y1, x2, and y2 respectively

Output

The area and perimeter of the rectangle

Sample Input

x1 = 2, y1 = 7, x2 = 5, y2 = 3

Sample Output

Area = 12, Perimeter = 14

Coding Exercise

Write your code below. It is recommended​ that you try solving the exercise yourself before viewing the solution.

Get hands-on with 1200+ tech skills courses.