LIVE Course for free

Rated by 1 million+ students
Get app now
JEE MAIN 2023
JEE MAIN 2023 TEST SERIES
NEET 2023 TEST SERIES
NEET 2023
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
119 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()

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

...