Advertisement
Blessing988

Untitled

May 22nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. def is_parallelogram(my_list):
  2.     """
  3. [(x1, y1), (x2, y2), (x3, y3), (x4, y4)]
  4. If it is a parallelogram it must satisfy 3 conditions:
  5. 1. x2 - x1 = x3 - x4 and y2-y1 = y3-y4
  6. 2. x3 - x1 = x2 - x4 and y3-y1 = y2 - y4
  7. 3. x3 - x1 = x4 - x2 and y3 - y1 = y4 - y2
  8.    """
  9.     x1, y1, x2, y2, x3, y3, x4, y4 = my_list[0][0], my_list[0][1], my_list[1][0], my_list[1][1], my_list[2][0], my_list[2][1], my_list[3][0], my_list[3][1]
  10.  
  11.     if (x2-x1 == x3 - x4) and (y2-y1 == y3-y4):
  12.         return True
  13.  
  14.     elif (x3-x1 == x2-x4) and (y3-y1==y2-y4):
  15.         return True
  16.  
  17.     elif (x3-x1 == x4-x2) and (y3-y1 == y4-y2):
  18.         return True
  19.  
  20.     else:
  21.         return False
  22.  
  23. print(is_parallelogram([(0, 0), (1, 0), (1, 1), (0, 1)]))
  24. print(is_parallelogram([(0, 0), (2, 0), (1, 1), (0, 1)]))
  25. print(is_parallelogram([(0, 0), (1, 1), (1, 4), (0, 3)]))
  26. print(is_parallelogram([(0, 0), (1, 2), (2, 1), (3, 3)]))
  27. print(is_parallelogram([(0, 0), (1, 0), (0, 1), (1, 1)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement