w3ajay

tally tutorial point, ms word 2013, ms excel 2013, ms powerpoint 2010,ccc question with answer in hindi 2021, Tally Prime in hindi , tally prime,Python,in python,programming in python,python

Friday, July 26, 2024

Create a binary file with name and roll number. Search for a given roll number and display the name, if not found display appropriate message.

Create a binary file with name and roll number. Search for a given roll number and display the name, if not found display appropriate message.











program for write read and search data in binary file in python



#writing data in Binary file
import pickle
f=open("ram.dat","wb")
a=[]
while True:
    roll=int(input("Enter the Student Roll Number"))
    name=input("Enter the Student name")
    marks=int(input("Enter the Student marks"))
    b=[roll,name,marks]
    a.append(b)
    bottun=int(input("Press =1 For Continue and Press = 2 for Stop Program"))
    if bottun==2:
        break
pickle.dump(a,f)
f.close()
#Reading Data in Binary File
import pickle
f=open("ram.dat","rb")
data=pickle.load(f)
for i in data:
    print(i)
f.close()

#Searching Data in Binary File
import pickle
f=open("ram.dat","rb")
flag=0
roll=int(input("Enter the Student Roll Number"))
data=pickle.load(f)
for i in data:
    if i[0]==roll:
        print(i)
        flag=1
        break
    if flag==0:
        print("Data not fund........")  

f.close()


Output:






Please Like Share and Comment 


No comments:

Post a Comment

for more information please share like comment and subscribe