Skip to content
C

Encapsulated Bank Account

Mediumpython

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.

Input (stdin)

Output

Run your code to see output here...