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

38 lines
979 B
Python
Raw Normal View History

2017-12-03 13:05:05 +01:00
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
2017-12-03 15:40:52 +01:00
def is_numeric(InputList):
OutputLits = []
for i in range(len(InputList)):
t = InputList[i]
OutputLits.append(isinstance(t,(int, float)))
2017-12-16 00:19:41 +01:00
#print(isinstance(x,(int, float)))
2017-12-03 15:40:52 +01:00
return OutputLits
2017-12-16 00:19:41 +01:00
2017-12-03 15:40:52 +01:00
class Point:
2017-12-16 00:19:41 +01:00
def __add__(self, other):
if len(self.cor)!=len(other.cor):
raise DimensionError("DimesnsionError")
else:
return [i+j for (i,j) in zip(self.cor,other.cor)]
def __init__(self, cor):
if (is_numeric(cor)):
self.cor=cor
else:
raise Exception("Wrong input")
def __len__(self):
return len(self.cor)
def __str__(self):
return(str(self.cor))
2017-12-16 09:01:07 +01:00
def __to_string__(self):
return(str(self.cor))
2017-12-16 00:19:41 +01:00
class DimensionError(Exception):
def __init__(self, text):
self.text = text
def __str__(self):
return self.text
2017-12-03 15:40:52 +01:00
2017-12-16 00:19:41 +01:00
test=Point([2,5])
print(str(test))
print(len(test))