Search a record from binary file using Bank Account no
import pickle import os #function definition def search_accno(): try: z=0 tr=int(input("Enter accno to search ")) f=open("bank","rb") print("Accno","Name","Balance") while True: rec=pickle.load(f) if rec[0]==tr: z=1 print(rec[0],rec[1],rec[2]) except EOFError: f.close() if z==0: print("Record not found") except IOError: print("Unable to open the file") #function calling search_accno()
Search a record from binary file using Customer Name
import pickle import os #function definition def search_name(): try: z=0 tn=input("Enter Name to search ") tn=tn.upper() f=open("bank","rb") print("Accno","Name","Balance") while True: rec=pickle.load(f) if rec[1]==tn: z=1 print(rec[0],rec[1],rec[2]) except EOFError: f.close() if z==0: print("Record not found") except IOError: print("Unable to open the file") #function calling search_name()