commit 01d5aa7cb605be3c1c66c1c4464f13d9ed66a2fe Author: Sven Riwoldt Date: Tue Nov 3 07:01:14 2020 +0100 Vektorgrundgerüst diff --git a/vector.py b/vector.py new file mode 100644 index 0000000..7357ef6 --- /dev/null +++ b/vector.py @@ -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