Back to Freecodecamp

Step 6

curriculum/challenges/english/blocks/learn-special-methods-by-building-a-vector-space/65f0694fb2296f3caadf8347.md

latest933 B
Original Source

--description--

The length of a vector $\mathbf{a}$, or norm, is typically indicated as $\| \mathbf{a} \|$. It can be calculated as the square root of the sum of its squared components: \[ \| \mathbf{a} \| = \sqrt{a_1^2 + a_2^2 + \ldots + a_n^2} \]

Compute the vector norm and return the result from your norm method.

--hints--

Your norm method should use the provided formula to calculate and return a number representing the norm of the current vector instance. Do not approximate the value.

js
({ test: () => runPython(`
v1 = Vector(2, 2.5)
v2 = Vector(0, -1)
v3 = Vector(-5, -0.3)
assert v1.norm() == 3.2015621187164243
assert v2.norm() == 1
assert v3.norm() == 5.008991914547277
`) })

--seed--

--seed-contents--

py
--fcc-editable-region--
class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
    def norm(self):
        pass
--fcc-editable-region--