Vektorgrundgerüst
This commit is contained in:
21
vector.py
Normal file
21
vector.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
class Vector(object):
|
||||||
|
def __init__(self, coordinates):
|
||||||
|
try:
|
||||||
|
if not coordinates:
|
||||||
|
raise ValueError
|
||||||
|
self.coordinates = tuple(coordinates)
|
||||||
|
self.dimension = len(coordinates)
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError('The coordinates must be nonempty')
|
||||||
|
|
||||||
|
except TypeError:
|
||||||
|
raise TypeError('The coordinates must be an iterable')
|
||||||
|
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Vector: {}'.format(self.coordinates)
|
||||||
|
|
||||||
|
|
||||||
|
def __eq__(self, v):
|
||||||
|
return self.coordinates == v.coordinates
|
||||||
Reference in New Issue
Block a user