Abhisek92

[Temp] Polygon.py

Jan 22nd, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. class Point(object):
  2.     def __init__(self, arg):
  3.         try:
  4.             if isinstance(arg, tuple):
  5.                 if all(isinstance(element, (int, float)) for element in arg):
  6.                     if len(arg) <= 3 and len(arg) > 0:
  7.                         self.__dimension = len(arg)
  8.                         self.__point = arg
  9.                     else:
  10.                         raise DimError("Dimension Error: Expected maximum 3 dimensions")
  11.                 else:
  12.                     raise TypeError("Type Error: Expected <float/int>")
  13.             else:
  14.                 raise ArgumentError("Argument Error: Expected <tuple>")
  15.         except TypeError as type_exception:
  16.             print(type_exception)
  17.  
  18. class Line(object):
  19.     def __init__(self, line):
  20.         try:
  21.             if isinstance(line, tuple):
  22.                 if len(line) == 2:
  23.                     if all(isinstance(element, Point) for element in line):
  24.                         self.__start = line[0]
  25.                         self.__end = line[1]
  26.                     else:
  27.                         raise TypeError("Type Error: Expected pair of Points")
  28.                 else:
  29.                     raise SizeError("Size Error: Expected one pair of Points")
  30.             else:
  31.                 raise TypeError("Argument Error: Expected <tuple>")
  32.         except TypeError as type_exception:
  33.             print(type_exception)
  34.         except SizeError as size_exception:
  35.             print(size_exception)
Add Comment
Please, Sign In to add comment