#!/usr/bin/env python2 # -*- coding: utf-8 -*- class Point(object): def __init__(self, coords): from labs04.task01 import is_numeric assert is_numeric(coords) self.coords = coords def add(self, that): if len(self.coords) != len(that.coords): raise DimensionError('Niezgodne wymiary') else: pass return Point(map(lambda(a,b): a+b, zip(self.coords, that.coords))) def to_string(self): return type(self).__name__+'('+((',').join(map(str, self.coords)))+')' def len(self): return len(self.coords) def __len__(self): return len(self.coords) def __str__(self): return self.to_string() def __add__(self, other): return self.add(other) class DimensionError(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return self.msg pt1 = Point([1,2,3.0,4.0]) pt2 = Point([-1, -2.0, -3, -4.0]) print('len(%s + %s) = %d' %(pt1, pt2, len(pt1 + pt2))) print(pt1 + pt2)