Computer Science, asked by Golu4095, 8 months ago

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

Answers

Answered by preranashinde386
12

Answer:

import pickle

#creating the file and writing the data

f=open("records.dat", "wb")

pickle.dump(["Wakil", 1], f)

pickle.dump(["Tanish", 2], f)

pickle.dump(["Priyashi", 3], f)

pickle.dump(["Kanupriya", 4], f)

pickle.dump(["Aaheli", 5], f)

f.close()

#opeining the file to read contents

f=open("records.dat", "rb")

n=int(input("Enter the Roll Number: "))

flag = False

while True:

   try:

       x=pickle.load(f)

       if x[1]==n:

           print("Name: ", x[0])

           flag = True

   except EOFError:

       break

if flag==False:

   print("This Roll Number does not exist")

Explanation:

hope it will help you
please mark me as brainst

Similar questions