#!/usr/bin/env python2 # -*- coding: utf-8 -*- import task01 class DimensionError(Exception): pass class Point: pointList = [] def __init__(self, coord): if isinstance(coord, list): if task01.is_numeric(coord): self.coord = coord self.x = coord[0] self.y = coord[1] if len(coord) == 3: self.z = coord[2] self.pointList.append(self.coord) else: print 'NOT all elements in the list are integers or floats' else: raise DimensionError('The argument must be a list') def add(self, point1, point2): point3 = [] if isinstance(point1, Point) and isinstance(point2, Point): point3.append(point1.x + point2.x) point3.append(point1.y + point2.y) point3.append(point1.z + point2.z) return Point(point3) else: print 'Arguments must be Points' def __len__(self): return len(self.coord) def to_string(self): return 'Point coordinates: x: {0} y: {1} z: {2}'.format(self.x, self.y, self.z) def __str__(self): print self.to_string()