Private Attributes and Name Mangling

Medium Encapsulation & Data Hiding
Solve in Playground →

Problem Statement

Create an `Account` class that sets a strictly private attribute `__balance` in its constructor. In the main block, try to access `__balance` directly. Catch the `AttributeError` and print ‘Cannot access’.

Input Format

A single integer for balance.

Output Format

Print 'Cannot access' due to name mangling.

Constraints

None

Sample Input

1000

Sample Output

Cannot access

Explanation

Python renames variables prefixed with a double underscore to `_ClassName__var` to hide them, raising an error on direct access.

Starter Code

class Account:
    # Set private __balance here
    pass

if __name__ == '__main__':
    b = int(input())
    acc = Account(b)
    try:
        # Attempt direct access and print it
        pass
    except AttributeError:
        print('Cannot access')

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