Author: Raj Aryan | Published: April 30, 2025
In this blog, I'll walk you through how I developed a Bank Management System using Python. This system supports basic banking functionalities like creating accounts, depositing money, and checking balances.
The bank management system presented here is implemented using Python. It provides functionalities such as account creation, deposit, withdrawal, updating account details, and checking balances. Below, I elaborate on the key points and provide detailed explanations of important code snippets and keywords.
The program begins by importing several essential modules:
import pickle
import datetime
import os
import random
The create() function allows users to create a new bank account.It ensures all necessary details are collected and validated before storing the account information.
def create():
f = open("bank.dat", "wb")
ans = 'y'
while ans == 'y':
while True:
accno = random.randint(10000000, 99999999)
r = acc_no(accno)
if r == 1:
break
name = input("Enter Account Name=").capitalize()
#(Other input fields: phone, address, city, email, date of birth, password)
deposit = int(input("Deposit Min^m rs500="))
while deposit < 500:
deposit += int(input("Add more money: "))
rec = [accno, name, phone, address, city, email, dob, passwd, deposit]
pickle.dump(rec, f)
print("....ACCOUNT SUCCESSFULLY CREATED...")
ans = input("Create More Account\nPRESS(y/n)=")
f.close()
The acc_no() function checks if an account number already exists.
def acc_no(a):
f = open("bank.dat", "rb")
found = False
try:
while True:
rec = pickle.load(f)
if rec[0] == a:
found = True
except:
if not found:
return 1
f.close()
The birth(dob) function ensures the provided date of birth is in the correct format and the user is at least 18 years old.
def birth(dob):
if dob[:4].isdigit() and dob[5:7].isdigit() and dob[8:10].isdigit() and dob[4] == '-' and dob[7] == '-':
if int(dob[:4]) < 2004:
# (Further validations for months and days)
return 1
else:
print("Invalid format")
def all_details():
f = open("bank.dat", "rb")
try:
while True:
rec = pickle.load(f)
print(rec)
except EOFError:
f.close()
The detail() function shows the details of a specific account.
def detail():
f = open("bank.dat", "rb")
accno = int(input("Enter account number"))
passwd = input("Enter password")
try:
while True:
rec = pickle.load(f)
if rec[0] == accno and rec[7] == passwd:
# (Print account details)
break
except EOFError:
print("Account Not Found")
f.close()
Authentication: Checks if the entered account number and password match.
The delete() function removes an account from the database.
def delete():
temp = open("temp.dat", "wb")
f = open("bank.dat", "rb")
accno = int(input("Enter account number"))
passwd = input("Enter account password")
found = False
try:
while True:
rec = pickle.load(f)
if rec[0] == accno and rec[7] == passwd:
found = True
continue
pickle.dump(rec, temp)
except EOFError:
if found:
os.remove("bank.dat")
os.rename("temp.dat", "bank.dat")
The update()function allows modification of account details.
def update():
accno = int(input("enter account no."))
passwd = input("enter account password")
f = open("bank.dat", "rb+")
try:
while True:
pos = f.tell()
rec = pickle.load(f)
if rec[0] == accno and rec[7] == passwd:
while True:
z = int(input("enter for update"))
if z == 1:
rec[1] = input("enter new name")
# (Other updates)
if z == 0:
break
f.seek(pos)
pickle.dump(rec, f)
break
except EOFError:
print("Account not found")
f.close()
Seek and Update: Uses f.seek(pos)to update the specific record in
place.
The deposit() function adds money to an account.
def deposit():
f = open("bank.dat", "rb+")
accno = int(input("Enter account number"))
passwd = input("Enter account password")
try:
while True:
pos = f.tell()
rec = pickle.load(f)
if rec[0] == accno and rec[7] == passwd:
d = int(input("Enter amount to deposit"))
rec[8] += d
f.seek(pos)
pickle.dump(rec, f)
break
except EOFError:
print("Account not found")
f.close()
OTP Verification: Ensures secure transactions using a randomly generated OTP.
def withdraw():
f = open("bank.dat", "rb+")
accno = int(input("Enter account number"))
passwd = input("Enter account password")
try:
while True:
pos = f.tell()
rec = pickle.load(f)
if rec[0] == accno and rec[7] == passwd:
d = int(input("Enter amount to withdraw"))
otp = random.randint(1000, 9999)
ou = int(input("Enter OTP"))
if otp == ou and rec[8] >= d:
rec[8] -= d
f.seek(pos)
pickle.dump(rec, f)
break
except EOFError:
print("Account not found")
f.close()
The balance() function shows the balance of an account.
def balance():
f = open("bank.dat", "rb")
accno = int(input("Enter account number"))
passwd = input("Enter password")
try:
while True:
rec = pickle.load(f)
if rec[0] == accno and rec[7] == passwd:
print("Balance=", rec[8])
break
except EOFError:
print("Account not found")
f.close()
The main menu handles user interactions and directs them to the appropriate functions based on their choices.
ch = None
while True:
print('*'*73)
print("TODAY'S DATE:", datetime.date.today(), "\tMAIN MENU\t")
ch = int(input("Enter Your Choice="))
if ch == 1:
create()
elif ch == 2:
while True:
ch1 = int(input("enter your choice="))
if ch1 == 1:
detail()
elif ch1 == 2:
balance()
elif ch1 == 3:
deposit()
elif ch1 == 4:
withdraw()
elif ch1 == 5:
break
elif ch == 0:
break
elif ch == 9:
key = 12345
p = int(input("Enter password To See Details"))
if key == p:
while True:
ch2 = int(input("Enter your choice="))
if ch2 == 1:
all_details()
elif ch2 == 2:
update()
elif ch2 == 3:
delete()
elif ch2 == 4:
break
else:
print("Wrong Password")
else:
print("Wrong choice")
This bank management system covers all essential functionalities required for basic banking operations. It ensures data validation, security (through OTPs and password protection), and provides a user-friendly interface for managing accounts and transactions. The use of pickle for data storage makes it easy to serialize and deserialize account information efficiently.
Full Code: GitHub