Overloading Addition (__add__)

Medium Magic Methods & Operator Overloading
Solve in Playground →

Problem Statement

Create a `Wallet` class initialized with a `balance`. Overload the `__add__` method to return a completely new `Wallet` object containing the combined balance. Read two balances, add the wallets, and print the new wallet’s balance.

Input Format

Two space-separated integers.

Output Format

Print 'New Balance: [total]'.

Constraints

None

Sample Input

50 75

Sample Output

New Balance: 125

Explanation

Overloading `__add__` enables adding complex objects directly with the `+` operator, abstracting the internal data structure.

Starter Code

class Wallet:
    # Define __init__ and __add__
    pass

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