Custom Truthiness Evaluation (__bool__)

Medium Magic Methods & Operator Overloading
Solve in Playground →

Problem Statement

Create a `BankAccount` class initialized with a `balance`. Overload the `__bool__` method to evaluate to `True` if `balance > 0`, and `False` otherwise. Read an integer, instantiate the account, and print `bool(account)`.

Input Format

A single integer.

Output Format

Print 'Is Active: [True/False]'.

Constraints

None

Sample Input

100

Sample Output

Is Active: True

Explanation

The `__bool__` method controls how an object is evaluated in conditional `if` statements or when passed to `bool()`.

Starter Code

class BankAccount:
    # Define __init__ and __bool__
    pass

if __name__ == '__main__':
    bal = int(input().strip())
    # Instantiate and evaluate
    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