Rectangle or Not? (Part 2)

Published by Donnamae in

Create a function that takes a list of 4 tuples. Each tuple consists of two numbers representing the x coordinate and y coordinate of a point on the Cartesian plane. Return True if these 4 points form a rectangle, False if they don't. Rectangles can be upright or tilted.

Examples

is_rectangle([(-1, -2), (-1, 3), (1, -1), (-3, 2)]) ➞ True

is_rectangle([(-1, -2), (-1, -2), (1, -1), (-3, 2)]) ➞ False

is_rectangle([(7, 4), (1, -2), (1, 4), (7, -2)]) ➞ True

Notes

  • A rectangle is a quadrilateral (4-sided polygon) with 4 right angles (90 degrees).
  • A square is a rectangle with all four sides equal.
Watch a quick demo on how Edabit works.