Operator Overloading: Customizing standard operations

Easy Magic Methods & Operator Overloading
Solve in Playground →

Problem Statement

Create a `Box` class that holds an integer `items`. Overload the addition operator `__add__` so that adding two `Box` objects returns a new `Box` with the sum of their items. Print the total items of the combined box.

Input Format

Two space-separated integers representing the items in Box 1 and Box 2.

Output Format

Print the combined items.

Constraints

Items >= 0

Sample Input

5 10

Sample Output

Total Items: 15

Explanation

Operator overloading allows you to define custom behavior for standard Python operators like `+` using magic methods.

Starter Code

class Box:
    # Define __init__ and __add__
    pass

if __name__ == '__main__':
    i1, i2 = map(int, input().split())
    # Instantiate boxes, add them, 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