diff --git a/bank_account.py b/bank_account.py new file mode 100644 index 0000000..837979a --- /dev/null +++ b/bank_account.py @@ -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 \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..2078d31 --- /dev/null +++ b/main.py @@ -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())