File tree Expand file tree Collapse file tree 1 file changed +46
-5
lines changed Expand file tree Collapse file tree 1 file changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,49 @@ def display_balance(self):
39
39
print (f"Interest Rate: { self .interest_rate * 100 } %" )
40
40
41
41
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 ("\n Select 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." )
You can’t perform that action at this time.
0 commit comments