Encapsulated Bank Account
Create a BankAccount class with a private _balance attribute, and methods deposit(), withdraw() (refusing withdrawals greater than the balance), and getbalance().
What the problem means: the account's balance should never be changeable directly from outside the class — every change must go through a controlled method that can enforce rules, like refusing an overdraw.
Approach: store the balance as self.__balance (double-underscore, private by convention). deposit() adds to it. withdraw() only subtracts if the amount doesn't exceed the current balance, otherwise it refuses.
Input: Three lines: the starting balance, a deposit amount, and a withdrawal amount to attempt.
Output: One line: Balance: <new balance> if the withdrawal succeeded, or Insufficient balance if it was refused.
0 1000 1500
Insufficient balance
- 0 <= amounts <= 10^9
Hint 1
self.__balance (double underscore) is private by Python's naming convention — outside code can't read or set it directly.
Hint 2
withdraw() should compare amount to self.__balance before subtracting anything.
Hint 3
Have withdraw() return True on success and False when refused, so the calling code can decide what to print.
_balance is private, so it can only be changed through the class's own methods. deposit() simply adds to it. withdraw() first checks whether the requested amount exceeds the current balance — if so it refuses (returns False) without touching the balance at all; otherwise it subtracts the amount and returns True, letting the caller print the new balance via getbalance().