diff --git a/classes.py b/classes.py new file mode 100644 index 0000000..786e6f2 --- /dev/null +++ b/classes.py @@ -0,0 +1,32 @@ +class BankAccount: + + def __init__(self, account_holder: str, initial_balance: float = 0): + self.__account_holder = account_holder + self.__balance = initial_balance + + def deposit(self, amount: float): + if not isinstance(amount, (int, float)): + raise TypeError("Deposit amount must be a number.") + if amount <= 0: + raise ValueError("Deposit amount must be positive.") + self.__balance += amount + return self.__balance + + def withdraw(self, amount: float): + if not isinstance(amount, (int, float)): + raise TypeError("Withdrawal amount must be a number.") + + if amount <= 0: + raise ValueError("Withdrawal amount must be positive.") + + if amount > self.__balance: + raise ValueError("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..4651158 --- /dev/null +++ b/main.py @@ -0,0 +1,32 @@ +from classes import BankAccount + + +bank_account1= BankAccount("Norah", 1000) + +name= bank_account1.get_account_holder() +balance = bank_account1.get_balance() +deposit= bank_account1.deposit(2500) + +print( + f"Account Holder: {name}\n" + f"The balance is: {balance}\n" + f"After deposit: {deposit}" +) + +print("-"*15) + +bank_account2= BankAccount("Sarah") +name2=bank_account2.get_account_holder() +balance2=bank_account2.get_balance() +deposit2= bank_account2.deposit(1500) +withdraw= bank_account2.withdraw(500) + +print( + f"Account Holder: {name2}\n" + f"The balance is: {balance2}\n" + f"After deposit: {deposit2}\n" + f"After withdraw {withdraw}" +) + + +