'''
Practical No: 7: WAP in Python to create a binary file with name and roll number
of the students. Search for a given roll number and display the name of student.
'''
import pickle
S={}
f=open('stud.dat','wb')
c='y'
while c=='y' or c=='Y':
rno=int(input("Enter the roll no. of the student : "))
name=input("Enter the name of the student: ")
S['RollNo']=rno
S['Name']=name
pickle.dump(S,f)
c=input("Do You Want to add more students(y/n): ")
f.close()
f=open('stud.dat','rb')
rno=int(input("Enter the roll no. of the student to be search: "))
K={}
m=0
try:
while True:
K=pickle.load(f)
if K["RollNo"] == rno:
print(K)
m=m+1
except EOFError:
f.close()
if m==0:
print("Student not Found")
No comments:
Post a Comment