Introduction
Here’s source code for a banking project in Python. The
following program has these features:
It allows users to open new accounts
Users can make transactions by entering the respective
amounts
Users can check the balance of their accounts
Admin can view a list of users to see how many users there
are along with their details
As you can see, it is quite basic, and you can add more
functionalities according to your requirements.
1
import pickle
importos
importpathlib
class Account :
accNo = 0
name = “
deposit=0
type = “
defcreateAccount(self):
self.accNo= int(input(“Enter the account no : “))
self.name = input(“Enter the account holder name : “)
self.type = input(“Ente the type of account [C/S] : “)
self.deposit = int(input(“Enter The Initial amount(>=500 for Saving
and >=1000 for current”))
print(“\n\n\nAccount Created”)
defshowAccount(self):
print(“Account Number : “,self.accNo)
print(“Account Holder Name : “, self.name)
print(“Type of Account”,self.type)
print(“Balance : “,self.deposit)
2
defmodifyAccount(self):
print(“Account Number : “,self.accNo)
self.name = input(“Modify Account Holder Name :”)
self.type = input(“Modify type of Account :”)
self.deposit = int(input(“Modify Balance :”))
defdepositAmount(self,amount):
self.deposit += amount
defwithdrawAmount(self,amount):
self.deposit -= amount
def report(self):
print(self.accNo, ” “,self.name ,” “,self.type,” “, self.deposit)
defgetAccountNo(self):
returnself.accNo
defgetAcccountHolderName(self):
return self.name
defgetAccountType(self):
returnself.type
defgetDeposit(self):
returnself.deposit
def intro():
3
print(“\t\t\t\t**********************”)
print(“\t\t\t\tBANK MANAGEMENT SYSTEM”)
print(“\t\t\t\t**********************”)
print(“\t\t\t\tBrought To You By:”)
print(“\t\t\t\tprojectworlds.in”)
input()
defwriteAccount():
account = Account()
account.createAccount()
writeAccountsFile(account)
defdisplayAll():
file = pathlib.Path(“accounts.data”)
iffile.exists ():
infile = open(„accounts.data‟,‟rb‟)
mylist = pickle.load(infile)
for item in mylist :
print(item.accNo,” “, item.name, ” “,item.type, ” “,item.deposit )
infile.close()
else :
print(“No records to display”)
4
defdisplaySp(num):
file = pathlib.Path(“accounts.data”)
iffile.exists ():
infile = open(„accounts.data‟,‟rb‟)
mylist = pickle.load(infile)
infile.close()
found = False
for item in mylist :
ifitem.accNo == num :
print(“Your account Balance is = “,item.deposit)
found = True
else :
print(“No records to Search”)
if not found :
print(“No existing record with this number”)
defdepositAndWithdraw(num1,num2):
file = pathlib.Path(“accounts.data”)
iffile.exists ():
infile = open(„accounts.data‟,‟rb‟)
mylist = pickle.load(infile)
5
infile.close()
os.remove(„accounts.data‟)
for item in mylist :
ifitem.accNo == num1 :
if num2 == 1 :
amount = int(input(“Enter the amount to deposit : “))
item.deposit += amount
print(“Your account is updted”)
elif num2 == 2 :
amount = int(input(“Enter the amount to withdraw : “))
if amount <= item.deposit :
item.deposit -=amount
else :
print(“You cannot withdraw larger amount”)
else :
print(“No records to Search”)
outfile = open(„newaccounts.data‟,‟wb‟)
pickle.dump(mylist, outfile)
outfile.close()
os.rename(„newaccounts.data‟, „accounts.data‟)
6
defdeleteAccount(num):
file = pathlib.Path(“accounts.data”)
iffile.exists ():
infile = open(„accounts.data‟,‟rb‟)
oldlist = pickle.load(infile)
infile.close()
newlist = []
for item in oldlist :
ifitem.accNo != num :
newlist.append(item)
os.remove(„accounts.data‟)
outfile = open(„newaccounts.data‟,‟wb‟)
pickle.dump(newlist, outfile)
outfile.close()
os.rename(„newaccounts.data‟, „accounts.data‟)
defmodifyAccount(num):
file = pathlib.Path(“accounts.data”)
iffile.exists ():
infile = open(„accounts.data‟,‟rb‟)
oldlist = pickle.load(infile)
7
infile.close()
os.remove(„accounts.data‟)
for item in oldlist :
ifitem.accNo == num :
item.name = input(“Enter the account holder name : “)
item.type = input(“Enter the account Type : “)
item.deposit = int(input(“Enter the Amount : “))
outfile = open(„newaccounts.data‟,‟wb‟)
pickle.dump(oldlist, outfile)
outfile.close()
os.rename(„newaccounts.data‟, „accounts.data‟)
defwriteAccountsFile(account) :
file = pathlib.Path(“accounts.data”)
iffile.exists ():
infile = open(„accounts.data‟,‟rb‟)
oldlist = pickle.load(infile)
oldlist.append(account)
infile.close()
os.remove(„accounts.data‟)
else :
8
oldlist = [account]
outfile = open(„newaccounts.data‟,‟wb‟)
pickle.dump(oldlist, outfile)
outfile.close()
os.rename(„newaccounts.data‟, „accounts.data‟)
# start of the program
ch=”
num=0
intro()
whilech != 8:
#system(“cls”);
print(“\tMAIN MENU”)
print(“\t1. NEW ACCOUNT”)
print(“\t2. DEPOSIT AMOUNT”)
print(“\t3. WITHDRAW AMOUNT”)
print(“\t4. BALANCE ENQUIRY”)
print(“\t5. ALL ACCOUNT HOLDER LIST”)
print(“\t6. CLOSE AN ACCOUNT”)
print(“\t7. MODIFY AN ACCOUNT”)
print(“\t8. EXIT”)
9
print(“\tSelect Your Option (1-8) “)
ch = input()
#system(“cls”);
ifch == „1‟:
writeAccount()
elifch ==‟2′:
num = int(input(“\tEnter The account No. : “))
depositAndWithdraw(num, 1)
elifch == „3‟:
num = int(input(“\tEnter The account No. : “))
depositAndWithdraw(num, 2)
elifch == „4‟:
num = int(input(“\tEnter The account No. : “))
displaySp(num)
elifch == „5‟:
displayAll();
elifch == „6‟:
num =int(input(“\tEnter The account No. : “))
deleteAccount(num)
elifch == „7‟:
10
num = int(input(“\tEnter The account No. : “))
modifyAccount(num)
elifch == „8‟:
print(“\tThanks for using bank management system”)
break
else :
print(“Invalid choice”)
ch = input(“Enter your choice : “)
11
Output
12
13
14