1
0
forked from tdwojak/Python2017
Python2017/labs04/task03.py

42 lines
988 B
Python
Raw Normal View History

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])
print(pt1 + pt2)