From e6733952254a45ab5647ee5e7c23c6ce9d440024 Mon Sep 17 00:00:00 2001 From: Daniyal Asif <147508972+Daniyal0100101@users.noreply.github.com> Date: Fri, 16 May 2025 15:48:32 +0500 Subject: [PATCH 1/2] Create bank_account_system.py Added an OOP-based Bank Account System using Python --- SimpleBankSystem/bank_account_system.py | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 SimpleBankSystem/bank_account_system.py diff --git a/SimpleBankSystem/bank_account_system.py b/SimpleBankSystem/bank_account_system.py new file mode 100644 index 0000000..7479b30 --- /dev/null +++ b/SimpleBankSystem/bank_account_system.py @@ -0,0 +1,46 @@ +class BankAccount: + def __init__(self, account_holder, balance): + self.account_holder = account_holder + self.__balance = balance + + def deposit(self, amount): + if amount > 0: + self.__balance += amount + print(f"Deposited {amount}") + else: + print("Invalid deposit amount") + + def withdraw(self, amount): + if 0 < amount <= self.__balance: + self.__balance -= amount + print(f"Withdrawn {amount}") + else: + print("Insufficient balance or invalid amount") + + def get_balance(self): + return self.__balance + + def display_balance(self): + print(f"Account Holder: {self.account_holder}") + print(f"Balance: {self.__balance}") + +class SavingsAccount(BankAccount): + def __init__(self, account_holder, balance, interest_rate): + super().__init__(account_holder, balance) + self.interest_rate = interest_rate + + def apply_interest(self): + interest = self.get_balance() * self.interest_rate + self.deposit(interest) + print("Interest applied") + + def display_balance(self): + super().display_balance() + print(f"Interest Rate: {self.interest_rate * 100}%") + +if __name__ == "__main__": + acc = SavingsAccount("John Doe", 1000, 0.05) + acc.deposit(500) + acc.withdraw(200) + acc.apply_interest() + acc.display_balance() From f25d019b4fd116db8bc30510b63dcdb2f926f98b Mon Sep 17 00:00:00 2001 From: Daniyal0100101 Date: Fri, 16 May 2025 19:47:24 +0500 Subject: [PATCH 2/2] Added user input functionality to bank account system --- SimpleBankSystem/bank_account_system.py | 51 ++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/SimpleBankSystem/bank_account_system.py b/SimpleBankSystem/bank_account_system.py index 7479b30..3a34b91 100644 --- a/SimpleBankSystem/bank_account_system.py +++ b/SimpleBankSystem/bank_account_system.py @@ -39,8 +39,49 @@ def display_balance(self): print(f"Interest Rate: {self.interest_rate * 100}%") if __name__ == "__main__": - acc = SavingsAccount("John Doe", 1000, 0.05) - acc.deposit(500) - acc.withdraw(200) - acc.apply_interest() - acc.display_balance() + print("=== Welcome to the Savings Account System ===") + name = input("Enter account holder name: ") + + try: + balance = float(input("Enter initial balance: ")) + interest_rate = float(input("Enter interest rate (e.g., 0.05 for 5%): ")) + except ValueError: + print("Invalid input. Exiting.") + exit() + except Exception as e: + print(f"An error occurred: {str(e)}") + exit() + + acc = SavingsAccount(name, balance, interest_rate) + + while True: + print("\nSelect an option:") + print("1. Deposit") + print("2. Withdraw") + print("3. Apply Interest") + print("4. Display Balance") + print("5. Exit") + + choice = input("Enter your choice (1-5): ") + + if choice == '1': + try: + amount = float(input("Enter amount to deposit: ")) + acc.deposit(amount) + except ValueError: + print("Invalid amount.") + elif choice == '2': + try: + amount = float(input("Enter amount to withdraw: ")) + acc.withdraw(amount) + except ValueError: + print("Invalid amount.") + elif choice == '3': + acc.apply_interest() + elif choice == '4': + acc.display_balance() + elif choice == '5': + print("Thank you! Exiting.") + break + else: + print("Invalid choice. Please select again.")