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
5.0k views
in Computer by (20 points)
WAP in Python to create a binary file with roll number, name and marks. Input a roll number and update the marks.

Please log in or register to answer this question.

1 Answer

0 votes
by (20 points)
import pickle
def Write():
    f = open("Studentdetails.dat", 'wb')
    while True:
        r =int(input ("Enter Roll no : "))
        n = input("Enter Name : ")
        m = int(input ("Enter Marks : "))
        record = [r,n,m]
        pickle.dump(record,f)
        ch = input("Do you want to enter more ?(Y/N)")
        if ch in 'Nn':
            break
        f.close()
def Read():
    f = open("Studentdetails.dat",'rb')
    try:    
        while True:
            rec=pickle.load(f)
            print(rec)
    except EOFError:
        f.close()
def Update():
    f = open("Studentdetails.dat", 'rb+')
    rollno = int(input("Enter roll no whoes marks you want to update"))
    try:
        while True:
            pos=f.tell()
            rec = pickle.load(f)
            if rec[0]==rollno:
                um = int(input("Enter Update Marks:"))
                rec[2]=um
                f.seek(pos)
                pickle.dump(rec,f)
                #print(rec)
    except EOFError:
        f.close()
Write()
Read()
Update()
Read()

Related questions

0 votes
1 answer
asked 5 days ago in Physics by Isimah (355 points)
0 votes
1 answer
asked 5 days ago in Physics by Isimah (355 points)
0 votes
1 answer
asked Jan 29, 2023 in Physics by rex4568 (984 points)
0 votes
0 answers

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

...