2017-12-03 13:05:05 +01:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-12-16 02:44:01 +01:00
|
|
|
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])
|
2017-12-16 02:51:57 +01:00
|
|
|
print('len(%s + %s) = %d' %(pt1, pt2, len(pt1 + pt2)))
|
2017-12-16 02:44:01 +01:00
|
|
|
print(pt1 + pt2)
|
|
|
|
|