2017-12-03 13:05:05 +01:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-12-15 17:50:29 +01:00
|
|
|
from task01 import *
|
|
|
|
|
|
|
|
class DimensionError(Exception):
|
|
|
|
def __init__(self, text):
|
|
|
|
self.text = text
|
|
|
|
def __str__(self):
|
|
|
|
return self.text
|
|
|
|
|
|
|
|
class Point:
|
|
|
|
|
|
|
|
def __init__(self, wspolrzedne):
|
|
|
|
if (is_numeric(wspolrzedne)):
|
|
|
|
self.wspolrzedne=wspolrzedne
|
|
|
|
else:
|
|
|
|
raise Exception("Non numerical coords")
|
|
|
|
def __len__(self):
|
|
|
|
return len(self.wspolrzedne)
|
|
|
|
def __str__(self):
|
|
|
|
return(str(self.wspolrzedne))
|
|
|
|
def to_string(self):
|
|
|
|
return str(self.wspolrzedne)
|
|
|
|
def __add__(self, other):
|
|
|
|
if len(self.wspolrzedne)!=len(other.wspolrzedne):
|
|
|
|
raise DimensionError("Elements have different dimensions!!1")
|
|
|
|
else:
|
|
|
|
return [i+j for (i,j) in zip(self.wspolrzedne,other.wspolrzedne)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pt=Point([1,2])
|
|
|
|
print(len(pt))
|
|
|
|
print(str(pt))
|
|
|
|
print(pt.to_string())
|
|
|
|
pt2=Point([7,99])
|
|
|
|
print(pt+pt2)
|
|
|
|
pt3=Point([1,2,3])
|
|
|
|
print(pt+pt3)
|
|
|
|
|