1
0
Fork 0

in progress

This commit is contained in:
Przemysław Kaczmarek 2017-12-14 20:02:17 +01:00
parent 8d38a7ddb4
commit aed06ae658
1 changed files with 53 additions and 10 deletions

View File

@ -1,23 +1,64 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
class DimensionError(Exception):
"""Discreapncies in dimensions. We cannot add points from different dimension"""
def __init__(self):
super().__init__(self)
self.msg='Discreapncies in dimensions. We cannot add points from different dimension'
class IsNumericError(Exception):
"""Point contains other chars than numbers"""
def __init__(self):
super().__init__(self)
self.msg='Point contains other chars than numbers'
class Point():
def __init__(self,list):
self.points=list
if len(list)==Point.is_numeric(self.points):
self.isnumeric=True
else:
self.isnumeric=False
try:
if Point.is_numeric(list)!=len(list):
self.points=[]
self.isnumeric = False
raise IsNumericError()
else:
self.points=list
self.isnumeric=True
except IsNumericError as e:
print(e.msg)
def __repr__(self):
return '<Point %s, is numeric: %s>' %(self.points,self.isnumeric)
def __add__(self, other):
new=[]
for index in range(len(self.points)):
new.append(self.points[index]+other.points[index])
try:
new = []
if self.isnumeric==False or other.isnumeric==False:
raise IsNumericError()
elif len(self.points) != len(other.points):
raise DimensionError()
else:
for index in range(len(self.points)):
new.append(self.points[index]+other.points[index])
except IsNumericError as e:
print(e.msg)
except DimensionError as e:
print(e.msg)
return new
def __len__(self):
len=0
try:
if self.isnumeric==False:
raise IsNumericError()
else:
for element in self.points:
len+=1
except IsNumericError as e:
print(e.msg)
return len
@staticmethod
def is_numeric(point):
value=0
@ -30,7 +71,9 @@ class Point():
def TestFunction():
punkt1=Point([12,12,2])
punkt2=Point([1,3,7])
punkt1=Point(['a',2,2])
punkt2=Point([1,7,25])
print(len(punkt1))
print(len(punkt2))
print(punkt1,punkt2,punkt1+punkt2)
TestFunction()