Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions bank_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class BankAccount:

def __init__(self, account_holder, initial_balance=0):
self.account_holder = account_holder


if initial_balance < 0:
self.balance = 0
else:
self.balance = initial_balance

def deposit(self, amount):
if amount <= 0:
raise ValueError("Deposit amount must be positive.")

self.balance += amount
return self.balance

def withdraw(self, amount):
if amount <= 0:
raise ValueError("Withdrawal amount must be positive.")

if amount > self.balance:
raise Exception("Insufficient funds.")

self.balance -= amount
return self.balance

def get_balance(self):
return self.balance

def get_account_holder(self):
return self.account_holder
16 changes: 16 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from bank_account import BankAccount

account1 = BankAccount("Wajn", 1000)

print("Account Holder:", account1.get_account_holder())
print("Initial Balance:", account1.get_balance())

account1.deposit(500)
print("Balance after deposit:", account1.get_balance())

try:
account1.withdraw(2000)
except Exception as eerror:
print("Error:", eerror)

print("Account Balance:", account1.get_balance())