-
Notifications
You must be signed in to change notification settings - Fork 0
/
__module.py
164 lines (131 loc) · 4.81 KB
/
__module.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def main(choice):
if choice == 1: # DEPOSIT
try:
amount = int(input("\nAmount to be Deposited: "))
except:
print("Invalid input!")
main(choice)
else:
mode = "deposited"
print("\nDeposit to Account Type")
print("A. Savings")
print("B. Current\n")
account = input("Account Type: ").upper().strip()
if account != 'A' and account != 'B':
print("Option not found: [A / B]")
main(choice)
else:
print()
account = "savings" if account == 'A' else "current"
perform_action(amount, account, mode)
elif choice == 2: # WITHDRAW
mode = "withdrawn"
try:
amount = int(input("\nAmount to be Withdrawn: "))
except:
print("Invalid input!")
main(choice)
else:
print("\nAccount Type")
print("A. Savings")
print("B. Current\n")
account = input("Account Type: ").upper().strip()
if account != 'A' and account != 'B':
print("Option not found: [A / B]\n")
main(choice)
else:
print()
account = "savings" if account == 'A' else "current"
withdraw_isvalid(amount, account, mode)
perform_action(amount, account, mode)
elif choice == 3: # FUND TRANSFER
mode = 'transferred'
try:
amount = int(input("\nAmount to be Transferred: "))
except:
print("Invalid input!")
main(choice)
else:
print("\nTransfer From - To Account Type:")
print("A. Savings to Current")
print("B. Current to Savings\n")
account = input("Account Type: ").upper().strip()
if account != 'A' and account != 'B':
print("Option not found: [A / B]\n")
main(choice)
else:
print()
account = "savings" if account == 'A' else "current"
withdraw_isvalid(amount, account, mode)
perform_action(amount, account, mode)
elif choice == 4: # BALANCE INQUIRY
print(f"\nSavings Balance: {user_balance['savings']}")
print(f"Current Balance: {user_balance['current']}\n")
run_again()
else:
print("Thank you for banking with us. Please remove your card...")
exit()
def perform_action(amt, acc, mode):
if mode == 'deposited':
user_balance[acc] += amt
elif mode == "withdrawn":
user_balance[acc] -= amt
elif mode == 'transferred':
tran_from = acc
receiver = "current" if acc == 'savings' else "savings"
user_balance[acc] -= amt
user_balance[receiver] += amt
acc = receiver
print(f"Amount of {amt} is {mode} {'from' if mode == 'withdrawn' else 'to'} {acc.capitalize()} Account.")
if mode == 'transferred':
print(f"{tran_from.capitalize()} Balance: {user_balance[tran_from]}")
print(f"{acc.capitalize()} Balance: {user_balance[acc]}\n")
run_again()
def choose_tran():
print("\nChoose a Transaction:")
for i in range(len(transactions)):
print(f"{i + 1} - {transactions[i]}")
print()
def input_choice():
while True:
try:
choice = int(input("Your Choice: "))
if choice > 5 or choice < 1:
raise Exception
except:
print("Invalid choice!\n")
else:
return choice
def withdraw_isvalid(amt, acc, mode):
mode = 'transfer' if mode == 'transferred' else 'withdraw'
if amt < 200:
print(f"Cannot {mode} amount of less than 200.")
choose_tran()
main(input_choice())
elif amt % 100 != 0:
print(f"{mode.capitalize()} amount must be in multiple of 100.")
print("(Ex. [200, 500, 1000, 2000, etc...])")
choose_tran()
main(input_choice())
elif amt > user_balance[acc]:
print(f"Error: cannot {mode} more than remaining balance")
print(f"{acc.capitalize()} balance: {user_balance[acc]}")
print(f"{mode.capitalize()} amount attempted: {amt}")
choose_tran()
main(input_choice())
def run_again():
run = input("Do you want to do another Transaction? [y/n]: ").lower().strip()
if run == 'y':
choose_tran()
main(input_choice())
elif run == 'n':
print("Thank you for banking with us. Please remove your card...")
exit()
else:
print("Option not found!\n")
run_again()
user_balance = {
"savings": 0,
"current": 0
}
transactions = ["Deposit", "Withdraw", "Fund Transfer", "Balance Inquiry", "Exit"]