-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingApplication.py
More file actions
31 lines (26 loc) · 1.12 KB
/
BankingApplication.py
File metadata and controls
31 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class BankAccount:
"""A simple BankAccount class."""
def __init__(self, account_holder: str, initial_balance: float = 0.0):
"""Initialize the account with the account holder's name and initial balance."""
self.account_holder = account_holder
self.balance = initial_balance
def deposit(self, amount: float):
"""Deposit an amount into the account."""
if amount <= 0:
raise ValueError("Deposit amount must be positive.")
self.balance += amount
return self.balance
def withdraw(self, amount: float):
"""Withdraw an amount from the account."""
if amount <= 0:
raise ValueError("Withdrawal amount must be positive.")
if amount > self.balance:
raise ValueError("Insufficient balance.")
self.balance -= amount
return self.balance
def get_balance(self):
"""Return the current balance of the account."""
return self.balance
def __str__(self):
"""Return a string representation of the account."""
return f"BankAccount({self.account_holder}, Balance: {self.balance})"