Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
16.1k views
in Computer by (20 points)
Write a program in Python to 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.

Please log in or register to answer this question.

1 Answer

0 votes
by (20 points) 1 flag
edited by
import pickle
def write():
    D={}
    f=open("Studentdetails.dat","wb")
    while True:
        r = int(input ("Enter Roll no : "))
        n = input("Enter Name : ")
        D['Roll No'] = r
        D['Name'] = n
        pickle.dump(D,f)
        ch = input("More ? (Y/N)")
        if ch in 'Nn':
            break
    f.close()
def Search() :
    found = 0
    rollno= int(input("Enter Roll no Whose name you want to display :"))
    f = open("Studentdetails.dat", "rb")
    try:
        while True:
            rec = pickle.load(f)
            if rec['Roll No']==rollno:
                print(rec['Name'])
                found = 1
                break
    except EOFError:
        f.close()
    if found == 0:
        print("Sorry not Found....")
    f.close()
write()
Search()

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...