Build a Custom Vector2D Math Class

Hard Magic Methods & Operator Overloading PRO
🔒 Login to Unlock

Problem Statement

Combine magic methods! Build a `Vector2D` class with `x` and `y`. Overload `__add__` to add vectors, `__eq__` to compare them, and `__str__` to return “. Read four integers (x1, y1, x2, y2). Print their sum using `__str__` and whether they are equal.

Input Format

Four space-separated integers representing v1 and v2.

Output Format

Print the vector sum on line 1, and the boolean equality check on line 2.

Constraints

None

Sample Input

2 3 4 5

Sample Output

Sum: 
Equal: False

Explanation

Integrating multiple magic methods yields highly expressive, native-feeling Python objects ideal for mathematical operations.

Starter Code

class Vector2D:
    # Implement __init__, __add__, __eq__, and __str__
    pass

if __name__ == '__main__':
    x1, y1, x2, y2 = map(int, input().split())
    # Instantiate v1 and v2, add, compare, and print
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used