Sponsored Reserved space — layout preview until AdSense is connected
medium +20 pts

2D Vector dataclass

dataclass + operator overloading.

Implement `@dataclass class Vector2D(x: float, y: float)` with: - `__add__`, `__sub__` — vector operations - `__mul__(scalar: float)` — scalar multiplication - `dot(other) -> float` — dot product - `magnitude() -> float` — Euclidean length

Constraints

x, y are floats.

Example

v = Vector2D(3, 4)
v.magnitude()  # 5.0
Vector2D(1,2) + Vector2D(3,4)  # Vector2D(4,6)
20 points ~18 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

math.sqrt(x**2 + y**2) for magnitude.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected