4. To write a Python Program to Create a binary file with roll number and name.
Search for a given roll number and display the name, if not found display
appropriate message.
#Bin file create and search
import pickle
def create():
f=open(r'G:\Juliet 2023-2024\[Link]','wb')
rec=[]
while True:
rno=int(input("Enter roll no : "))
name=input('Enter name : ')
data=[rno,name]
[Link](data)
ch=input('Do you want to continue (y/n) : ')
if ch in 'Nn':
break
[Link](rec,f)
print('Record Added')
[Link]()
def search():
f=open(r'G:\Juliet 2023-2024\[Link]','rb')
r=int(input('Enter Roll no. of student to search : '))
found=0
try:
while True:
d=[Link](f)
for i in d:
if i[0]==r:
print('The searched roll no is found : ', i)
found=1
break
except EOFError:
[Link]()
if found==0:
print('The searched roll no is not found')
create()
search()