28 lines
666 B
Python
28 lines
666 B
Python
# -*- coding: iso-8859-15 -*
|
|
|
|
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('Die Koordinaten dürfen nicht leer sein')
|
|
|
|
except TypeError:
|
|
raise TypeError('Die Koordinaten müssen iterierbar sein')
|
|
|
|
|
|
def __str__(self):
|
|
return 'Vector: {}'.format(self.coordinates)
|
|
|
|
|
|
def __eq__(self, v):
|
|
return self.coordinates == v.coordinates
|
|
|
|
# Tests
|
|
|
|
vektor_1 = Vector([1,2,3])
|
|
print vektor_1 |