Skip to main content
🐍 Python Projects

Bank Account Class

What you're building

A BankAccount class that tracks a balance, records a transaction history, and refuses withdrawals that would overdraw the account.

Requirements

  • deposit(amount) β€” add amount to balance; return new balance
  • withdraw(amount) β€” subtract amount if funds are available; return True on success, False on failure
  • balance property β€” current balance
  • history property β€” list of (type, amount) tuples, e.g. ("deposit", 100)
acc = BankAccount(100)
acc.deposit(50)    # balance β†’ 150
acc.withdraw(200)  # False (overdraft)
acc.withdraw(40)   # True,  balance β†’ 110

Stretch goals

  • Add a transfer(amount, other_account) method.
  • Raise ValueError for negative deposit/withdrawal amounts.

What this proves

OOP fundamentals β€” __init__, instance state, methods with return values, and defensive guards β€” the bread and butter of system design questions.

⚑ 40 XP
solution.pyRuns in your browser (Pyodide)
Loading editor…
Tests4 to pass
deposit increases balance
withdraw succeeds when funds available
withdraw fails when insufficient funds
history records transactions

Run your code to check these.