Skip to content

Commit f25d019

Browse files
Added user input functionality to bank account system
1 parent e673395 commit f25d019

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

SimpleBankSystem/bank_account_system.py

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,49 @@ def display_balance(self):
3939
print(f"Interest Rate: {self.interest_rate * 100}%")
4040

4141
if __name__ == "__main__":
42-
acc = SavingsAccount("John Doe", 1000, 0.05)
43-
acc.deposit(500)
44-
acc.withdraw(200)
45-
acc.apply_interest()
46-
acc.display_balance()
42+
print("=== Welcome to the Savings Account System ===")
43+
name = input("Enter account holder name: ")
44+
45+
try:
46+
balance = float(input("Enter initial balance: "))
47+
interest_rate = float(input("Enter interest rate (e.g., 0.05 for 5%): "))
48+
except ValueError:
49+
print("Invalid input. Exiting.")
50+
exit()
51+
except Exception as e:
52+
print(f"An error occurred: {str(e)}")
53+
exit()
54+
55+
acc = SavingsAccount(name, balance, interest_rate)
56+
57+
while True:
58+
print("\nSelect an option:")
59+
print("1. Deposit")
60+
print("2. Withdraw")
61+
print("3. Apply Interest")
62+
print("4. Display Balance")
63+
print("5. Exit")
64+
65+
choice = input("Enter your choice (1-5): ")
66+
67+
if choice == '1':
68+
try:
69+
amount = float(input("Enter amount to deposit: "))
70+
acc.deposit(amount)
71+
except ValueError:
72+
print("Invalid amount.")
73+
elif choice == '2':
74+
try:
75+
amount = float(input("Enter amount to withdraw: "))
76+
acc.withdraw(amount)
77+
except ValueError:
78+
print("Invalid amount.")
79+
elif choice == '3':
80+
acc.apply_interest()
81+
elif choice == '4':
82+
acc.display_balance()
83+
elif choice == '5':
84+
print("Thank you! Exiting.")
85+
break
86+
else:
87+
print("Invalid choice. Please select again.")

0 commit comments

Comments
 (0)