Back to Practice
#0166

Simple Bank Account Class

MediumPython25 min20 XP

Problem

Create a BankAccount class with balance, deposit(amount), and withdraw(amount). Withdraw should raise ValueError if amount exceeds balance.

Why This Matters

OOP interview questions often test state changes, validation, and method behavior rather than fancy inheritance.

Function Signature

class BankAccount:

Examples

Example 1
Inputstart 100, deposit 50, withdraw 30
Output120

100 + 50 - 30 leaves balance 120.

Constraints

  • Return the exact requested output.
  • Handle ordinary edge cases.
  • Prefer simple, interview-readable code.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputstart 100, deposit 50, withdraw 30
Expected120

100 + 50 - 30 leaves balance 120.

Hidden Test Categories
empty or minimal inputduplicates or tieslarger input