@@ -159,18 +159,18 @@ def change_component(self, pos: int, value: float) -> None:
159
159
def euclidean_length (self ) -> float :
160
160
"""
161
161
returns the euclidean length of the vector
162
- """
163
- squares = [c ** 2 for c in self .__components ]
164
- return math .sqrt (sum (squares ))
165
-
166
- def magnitude (self ) -> float :
167
- """
168
- Magnitude of a Vector
169
162
170
- >>> Vector([2, 3, 4]).magnitude ()
163
+ >>> Vector([2, 3, 4]).euclidean_length ()
171
164
5.385164807134504
172
-
165
+ >>> Vector([1]).euclidean_length()
166
+ 1
167
+ >>> Vector([]).euclidean_length()
168
+ Traceback (most recent call last):
169
+ ...
170
+ Exception: Vector is empty
173
171
"""
172
+ if len (self .__components ) == 0 :
173
+ raise Exception ("Vector is empty" )
174
174
squares = [c ** 2 for c in self .__components ]
175
175
return math .sqrt (sum (squares ))
176
176
@@ -188,7 +188,7 @@ def angle(self, other: Vector, deg: bool = False) -> float:
188
188
Exception: invalid operand!
189
189
"""
190
190
num = self * other
191
- den = self .magnitude () * other .magnitude ()
191
+ den = self .euclidean_length () * other .euclidean_length ()
192
192
if deg :
193
193
return math .degrees (math .acos (num / den ))
194
194
else :
@@ -267,17 +267,15 @@ class Matrix:
267
267
268
268
def __init__ (self , matrix : list [list [float ]], w : int , h : int ) -> None :
269
269
"""
270
- simple constructor for initializing
271
- the matrix with components.
270
+ simple constructor for initializing the matrix with components.
272
271
"""
273
272
self .__matrix = matrix
274
273
self .__width = w
275
274
self .__height = h
276
275
277
276
def __str__ (self ) -> str :
278
277
"""
279
- returns a string representation of this
280
- matrix.
278
+ returns a string representation of this matrix.
281
279
"""
282
280
ans = ""
283
281
for i in range (self .__height ):
@@ -291,7 +289,7 @@ def __str__(self) -> str:
291
289
292
290
def __add__ (self , other : Matrix ) -> Matrix :
293
291
"""
294
- implements the matrix- addition.
292
+ implements matrix addition.
295
293
"""
296
294
if self .__width == other .width () and self .__height == other .height ():
297
295
matrix = []
@@ -307,7 +305,7 @@ def __add__(self, other: Matrix) -> Matrix:
307
305
308
306
def __sub__ (self , other : Matrix ) -> Matrix :
309
307
"""
310
- implements the matrix- subtraction.
308
+ implements matrix subtraction.
311
309
"""
312
310
if self .__width == other .width () and self .__height == other .height ():
313
311
matrix = []
0 commit comments