-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank.py
220 lines (192 loc) · 8.14 KB
/
bank.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import random
def main():
print(" ******Welcome To ERC Banking System******\n")
name_list, acc_num_list, acc_blc_list = read_file()
option = 0
while option != 5:
# displaying option menu
banking_menu = [" 1. Open Account", " 2. Withdraw Money",
" 3. Deposit Money", " 4.display"," 5. Quit\n",]
for option in banking_menu:
print(option)
user_input = False
# validation for user input
while not user_input:
try:
option = int(input("Please enter an option:"))
if 0 < option < 7:
user_input = True
else:
print("\nPlease enter a number greater than 0 and less than 7\n")
for option in banking_menu:
print(option)
except:
print("\nError -- Please enter a number between 1 to 6 only\n")
for option in banking_menu:
print(option)
#print(name_list + acc_num_list + acc_blc_list)
# if statement for all of the options
if option == 1:
name_list, acc_num_list, acc_blc_list = open_acc(name_list, acc_num_list, acc_blc_list)
elif option == 2:
name_list, acc_num_list, acc_blc_list = cash_out(name_list, acc_num_list, acc_blc_list)
elif option == 3:
name_list, acc_num_list, acc_blc_list = add_money(name_list, acc_num_list, acc_blc_list)
elif option == 4 :
name_list, acc_num_list, acc_blc_list = display_acc(name_list, acc_num_list, acc_blc_list)
elif option == 5:
exit(name_list, acc_num_list, acc_blc_list)
# Functions for all of the switch statement
def read_file():
name_list = []
acc_num_list = []
acc_blc_list = []
# reading the text file
f = open("bank.txt", "r")
lines = f.readlines()
for line in lines:
information = line.split()
acc_num_list.append(information[0])
acc_blc_list.append(float(information[1]))
name_list.append(information[2])
return name_list, acc_num_list, acc_blc_list
# Function for opening an account
def open_acc(name_list, acc_num_list, acc_blc_list):
name = input("Please enter your name:")
print("Your name:", name)
name_list.append(name)
# found = True
# while found:
number = str(random.randint(1, 1000000))
# check the number
print("your account number:", number)
acc_num_list.append(number)
acc_blc_list.append(0.0)
return name_list, acc_num_list, acc_blc_list
# Function for closing an account
def shutdown_acc(name_list, acc_num_list, acc_blc_list):
account_number = input("\nEnter your account number:\n")
index = 0
found = False
for i in acc_num_list:
if i == account_number:
found = True
break
index = index + 1
if found:
print("\nSorry to see you go", name_list[index], "\n")
# deletes the 3 lists from their index position.
del acc_num_list[index]
del acc_blc_list[index]
del name_list[index]
else:
print("\nError -- No account exists under the number you provided\n")
return name_list, acc_num_list, acc_blc_list
# Function for Withdrawing money from an account
def cash_out(name_list, acc_num_list, acc_blc_list):
account_number = input("\nEnter your account number:\n")
index = 0
found = False
for i in acc_num_list:
if i == account_number:
found = True
break
index = index + 1
if found:
problem = True
while problem:
try:
withdraw_amount = float(input("Enter the amount you want to withdraw:"))
# The Amount is the new amount the customer has withdrawn
if withdraw_amount < 0: # if not a positive int print message and ask for input again
print("ERROR -- input must be a positive integer, try again")
break
amount = acc_blc_list[index] - withdraw_amount
# if the amount is greater than or = 0 it will take the amount away from the balance list.
if amount > 0:
acc_blc_list[index] = acc_blc_list[index] - withdraw_amount
print("An amount of ", format(withdraw_amount, ".2f"), " is removed from your account ",
account_numb4er,
sep="")
print("Your current balance is rs ", format(acc_blc_list[index], ".2f"), sep="")
print("")
problem = False
else:
print("Unfortunately you don't have a sufficient funds",
name_list[index])
print("Your balance after your current transaction is rs",
format(acc_blc_list[index], ".2f"), sep="")
print("")
break
finally:
return name_list, acc_num_list, acc_blc_list
else:
print("\n Sorry that account number does not exist \n")
return name_list, acc_num_list, acc_blc_list
# Function for depositing an amount to an account
def add_money(name_list, acc_num_list, acc_blc_list):
account_number = input("\nEnter your account number:\n")
index = 0
found = False
for i in acc_num_list:
if i == account_number:
found = True
break
index = index + 1
if found:
problem = True
while problem:
try:
deposit_amount = float(input("Enter the amount you want to deposit:"))
# The Amount of customer chooses to deposit
if deposit_amount < 0: # if not a positive int print message and ask for input again
print("ERROR -- input must be a positive integer, try again")
break
amount = acc_blc_list[index] + deposit_amount
# if the amount is greater than or = 0 it will added to the balance list.
if amount > 0:
acc_blc_list[index] = acc_blc_list[index] + deposit_amount
print("An amount of rs", format(deposit_amount, ".2f"), " is added from your account ",
account_number,
sep="")
print("Your current balance is rs", format(acc_blc_list[index], ".2f"), sep="")
print("")
problem = False
else:
print("Error -- Please enter a positive number",
name_list[index])
print("Your balance after your current transaction is rs",
format(acc_blc_list[index], ".2f"), sep="")
print("")
break
finally:
return name_list, acc_num_list, acc_blc_list
else:
print("\n Sorry that account number does not exist \n")
return name_list, acc_num_list, acc_blc_list
# Function to display a report for all the accounts details
def display_acc(name_list, acc_num_list, acc_blc_list):
account_number = input("\nEnter your account number:\n")
index = 0
found = False
for i in acc_num_list:
if i == account_number:
found = True
break
index = index + 1
if found:
problem = True
while problem:
print("************ERC banking passbook************")
print("##The Account number is",acc_num_list[index])
print("##The Account name is",name_list[index])
print("##The current balance of the account is",acc_blc_list[index],"rs")
return name_list, acc_num_list, acc_blc_list
def exit(name_list, acc_num_list, acc_blc_list):
print("Thank You For Using Our Banking System")
quit_file = open("bank.txt", "w")
for i in range(len(acc_num_list)):
save = acc_num_list[i] + " " + str(acc_blc_list[i]) + " " + name_list[i] + "\n"
quit_file.write(save)
quit_file.close()
main()