-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank_System.py
More file actions
196 lines (170 loc) · 5.22 KB
/
Copy pathBank_System.py
File metadata and controls
196 lines (170 loc) · 5.22 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
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
import random
import csv
import datetime
def create_new_account():
# Date for Account Creation
date = datetime.datetime.now()
ac_date = date.strftime("%d-%m-%Y %I:%M %p")
# Assigning a random AC number to the user
ac_no = random.randint(10000, 99999)
name = input("Enter Your Full Name: ").title()
email = input("Enter Your E-Mail ID: ").lower()
balance = 0
bal_after_creation = "Account Created"
# Assigning INFO to the CSV File
with open("accounts.csv", "a", newline="") as f:
accounts = csv.writer(f)
accounts.writerow([name, ac_no, email, ac_date, balance])
print(f"Name: {name}")
print(f"E-Mail ID: ", email)
print(f"AC No.: {ac_no}")
print(f"Please Note Down the AC Number for further transactions. Your AC no. is {ac_no}".upper())
# Creating new Document to store transaction details
with open("transactions.csv", "a", newline="") as f:
transactions = csv.writer(f)
transactions.writerow([ac_no, balance,bal_after_creation, ac_date])
def search_ac_no():
print("Enter Your Email ID to get your AC Number.".upper())
email = input("Enter E-Mail Address: ").lower()
found = False
with open("accounts.csv", "r") as f:
reader = csv.reader(f)
for i in reader:
if i[2] == email:
found = True
print("Name: ", i[0])
print("AC Number: ", i[1])
print("Date of Creation :", i[3])
if not found:
print("Invalid Email or Email Doesn't exist.")
def deposit():
ac = input("Enter AC Number: ")
updated_details = []
mode = "Credit"
found = False
date = datetime.datetime.now()
transac_date = date.strftime("%d-%m-%Y %I:%M %p")
with open("accounts.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
if row[1] == ac:
found = True
amount = int(input("Enter Amount: "))
row[4] = amount + int(row[4])
updated_details.append(row)
if not found:
print("AC Number Not Found")
else:
with open("accounts.csv", "w+", newline="") as f:
writer = csv.writer(f)
writer.writerows(updated_details)
with open("transactions.csv", "a", newline="") as f:
writer = csv.writer(f)
writer.writerow([ac, amount, mode, transac_date])
print(f"You Deposited Rs. {amount} Successfully")
def view_transactions():
ac = input("Enter AC Number: ")
count = 0
with open("transactions.csv", "r") as f:
reader = csv.reader(f)
for account in reader:
if ac == account[0]:
count +=1
print(f"{count}. Amount: {account[1]} | Mode: {account[2]} | Date: {account[3]}")
def withdraw():
ac = input("Enter AC Number: ")
updated_details = []
mode = "Debit"
found = False
date = datetime.datetime.now()
transac_date = date.strftime("%d-%m-%Y %I:%M %p")
with open("accounts.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
if ac == row[1]:
print(f"Balance: {row[4]}")
print()
found = True
amount =input("Enter Amount to Withdraw: ")
if int(amount) > int(row[4]):
print()
print("Insufficient Balance".upper())
else:
row[4] = int(row[4]) - int(amount)
updated_details.append(row)
if not found:
print()
print("Enter Valid AC Number")
else:
with open("accounts.csv", 'w+', newline="" ) as f:
writer = csv.writer(f)
writer.writerows(updated_details)
with open("transactions.csv", "a", newline="") as f:
writer = csv.writer(f)
writer.writerow([ac,amount, mode, transac_date])
print(f"You Withdrew Rs. {amount} Successfully")
def view_balance():
ac = input("Enter AC number: ")
with open("accounts.csv", 'r') as f:
reader = csv.reader(f)
for row in reader:
if row[1] == ac:
print(f"Balance: {row[4]}")
while True:
print('''*************
Welcome to Bank of Daroga
*************
[1] Create new Bank Account
[2] Search Account Number
[3] Withdraw
[4] Deposit
[5] View Balance
[6] View Previous Transactions
*************
[7] Exit
*************''')
ch = input("Enter Choice: ")
if ch == "1":
create_new_account()
break
elif ch == "2":
search_ac_no()
print('''*******
[1] Main Menu
[2] Quit
*******''')
ch1 = input("Enter Option: ")
if ch1 == "1":
continue
else:
break
elif ch == "3":
withdraw()
break
elif ch == "4":
deposit()
break
elif ch == "5":
view_balance()
print('''*******
[1] Main Menu
[2] Quit
*******''')
ch1 = input("Enter Option: ")
if ch1 == "1":
continue
else:
break
elif ch == "6":
view_transactions()
print('''*******
[1] Main Menu
[2] Quit
*******''')
ch1 = input("Enter Option: ")
if ch1 == "1":
continue
else:
break
elif ch == "6":
break