The main class for managing multiple bank accounts.
Bank(name: str = "Python Bank", storage_path: str = "bank_data.json")
Parameters:
name: Name of the bankstorage_path: Path to the data storage filecreate_account(account_type, account_number, account_holder, **kwargs)Create a new bank account.
Parameters:
account_type: Type of account (“checking”, “savings”, “business”)account_number: Unique account identifieraccount_holder: Name of the account holder**kwargs: Account-specific parametersReturns: BankAccount instance
Raises: AccountAlreadyExistsError, ValueError
Example:
bank = Bank()
account = bank.create_account(
account_type="checking",
account_number="CHK001",
account_holder="John Doe",
initial_balance=1000.0
)
get_account(account_number)Retrieve an account by its number.
Parameters:
account_number: Account identifierReturns: BankAccount instance
Raises: AccountNotFoundError
delete_account(account_number)Delete an account.
Parameters:
account_number: Account identifierRaises: AccountNotFoundError
list_accounts()Get a list of all accounts.
Returns: List[BankAccount]
get_total_balance()Calculate total balance across all accounts.
Returns: float
transfer(from_account_number, to_account_number, amount)Transfer money between accounts.
Parameters:
from_account_number: Source accountto_account_number: Destination accountamount: Amount to transferRaises: AccountNotFoundError, InsufficientFundsError, InvalidAmountError
save()Save all accounts to persistent storage.
load()Load accounts from persistent storage.
get_statistics()Get bank statistics.
Returns: Dictionary containing:
total_accounts: Total number of accountstotal_balance: Total balanceaccounts_by_type: Count by account typebalance_by_type: Total balance by typeAbstract base class for all account types.
BankAccount(account_number: str, account_holder: str, initial_balance: float = 0.0)
deposit(amount) (Abstract)Deposit money into the account.
withdraw(amount) (Abstract)Withdraw money from the account.
get_balance()Get the current balance.
Returns: float
get_transaction_history(limit=None)Get transaction history.
Parameters:
limit: Optional limit on number of transactionsReturns: List[Transaction]
get_account_type()Get the account type name.
Returns: str
to_dict()Convert account to dictionary.
Returns: dict
Checking account with overdraft protection and transaction fees.
CheckingAccount(
account_number: str,
account_holder: str,
initial_balance: float = 0.0,
overdraft_limit: float = 100.0,
transaction_fee: float = 0.0,
free_transactions: int = 5
)
Parameters:
account_number: Unique identifieraccount_holder: Account holder nameinitial_balance: Starting balanceoverdraft_limit: Maximum negative balance allowedtransaction_fee: Fee per transaction (after free transactions)free_transactions: Number of free transactions per monthdeposit(amount)Deposit money. May incur transaction fee.
withdraw(amount)Withdraw money. Allows overdraft up to limit.
reset_monthly_transactions()Reset the monthly transaction counter.
Savings account with interest and withdrawal limits.
SavingsAccount(
account_number: str,
account_holder: str,
initial_balance: float = 0.0,
interest_rate: float = 0.02,
minimum_balance: float = 100.0,
withdrawal_limit: int = 6
)
Parameters:
account_number: Unique identifieraccount_holder: Account holder nameinitial_balance: Starting balanceinterest_rate: Annual interest rate (as decimal)minimum_balance: Minimum required balancewithdrawal_limit: Maximum withdrawals per monthdeposit(amount)Deposit money into savings.
withdraw(amount)Withdraw money. Enforces minimum balance and withdrawal limit.
Raises: MinimumBalanceError, BankingException
add_interest()Calculate and add interest to balance.
Returns: float (interest amount)
reset_monthly_withdrawals()Reset the monthly withdrawal counter.
Business account with monthly fees.
BusinessAccount(
account_number: str,
account_holder: str,
business_name: str,
tax_id: str,
initial_balance: float = 0.0,
monthly_fee: float = 10.0
)
Parameters:
account_number: Unique identifieraccount_holder: Account holder namebusiness_name: Name of the businesstax_id: Tax identification numberinitial_balance: Starting balancemonthly_fee: Monthly maintenance feedeposit(amount)Deposit money into business account.
withdraw(amount)Withdraw money from business account.
charge_monthly_fee()Charge the monthly maintenance fee.
Base exception for all banking errors.
Raised when withdrawal exceeds available funds.
Attributes:
balance: Current balanceamount: Attempted withdrawal amountRaised for invalid transaction amounts.
Attributes:
amount: The invalid amountRaised when account doesn’t exist.
Attributes:
account_number: The account numberRaised when creating duplicate account.
Attributes:
account_number: The account numberRaised when balance falls below minimum.
Attributes:
balance: Current/resulting balanceminimum: Minimum required balanceHandles data persistence.
BankStorage(storage_path: str = "bank_data.json")
save(data)Save data to JSON file.
Parameters:
data: Dictionary to saveload()Load data from JSON file.
Returns: dict or None
delete()Delete the storage file.
backup(backup_path=None)Create a backup of the storage file.
Parameters:
backup_path: Optional custom backup pathReturns: Path to backup file