-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_Banking_System.py
More file actions
67 lines (58 loc) · 2.16 KB
/
Copy pathSimple_Banking_System.py
File metadata and controls
67 lines (58 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 2. Simple Banking System (Console App)
class InsufficientFundsError(Exception):
def __init__(self, amt, msg = "Your balance is insufficient to withdraw"):
self.amt = amt
self.msg = msg
super().__init__(self.msg)
def __str__(self):
return f"Transaction failed! {self.msg}.\n"
def transaction_history(stmt):
with open("transactions.txt", "a") as file:
file.write(stmt)
bal = 12000
ch = ""
while ch != '5':
print("Connnected to service! What do you like to choose?")
print("1. Deposit Money")
print("2. Withdraw Money")
print("3. Check balance")
print("4. Transaction History")
print("5. Exit")
ch = input("Enter your choice:")
try:
if ch == '1':
print("You are depositing the money...")
amt = int(input("Enter the amount you want to deposit:"))
if amt <= 0:
print("Amount must be greater than zero.\n")
continue
bal += amt
stmt = f"Rs.{amt} credited into your account.\n"
print(stmt)
transaction_history(stmt)
elif ch == '2':
print("You are withdrawing the money...")
amt = int(input("Enter the amount you want to wthdraw:"))
if amt <= 0:
print("Amount must be greater than zero.\n")
continue
if amt > bal:
raise InsufficientFundsError(amt)
bal -= amt
stmt = f"Rs.{amt} debited from your account.\n"
print(stmt)
transaction_history(stmt)
elif ch == '3':
print(f"Your bank balance: {bal}\n")
elif ch == '4':
with open("transactions.txt", "r") as file:
history = file.read()
print(history)
elif ch == '5':
print("Disconnected from service.....")
else:
print("Invalid input! Please enter choice number (1-4).\n")
except ValueError:
print("ERROR! Amount must be in numbers not in words.\n")
except InsufficientFundsError as e:
print(e)