0% found this document useful (0 votes)
17 views3 pages

Program 11

Uploaded by

rushda.7369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Program 11

Uploaded by

rushda.7369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM-11

UPDATE OPERATION IN A BINARY FILE


OBJECTIVE:
To write a menu driven program to create a binary file with roll number, name and marks.
Update the marks by 2, for the students who scored marks greater than 70 and not more than
90.

INPUT:
A text file with content.

OUTPUT:
Display name and updated marks of the students..

CODING:
import pickle
def Input():
f = open("Studentrecord.dat","ab")
n = int(input("How many records you want to create ?"))
for str in range(n):
sroll = int(input("Enter the roll number"))
name = input("Enter the name")
marks = int(input("Enter the marks"))
L = [sroll, name, marks]
pickle.dump(L,f)
f.close()
def Read():
f = open("Studentrecord.dat", "rb")
print(" \n DISPLAY STUDENT DETAILS ")
print("Roll no","\t","Name", "\t", "Marks")
try:
while True:
L = pickle.load(f)
print(L[0]," \t", L[1], "\t", L[2])
except EOFError:
f.close()
def Update_record():
f = open("Studentrecord.dat", "rb")
L1 = []
try:
while True:
L = pickle.load(f)
if L[2] > 70 and L[2] < 90:
L[2] = L[2] + 2
L1.append(L)
except:
f.close()
open("Studentrecord.dat", "wb")
for i in L1:
pickle.dump(i, f)
f.close()

while True:
print("\n Your choice :")
print("1. Insert records")
print("2. Display records")
print("3. Update Record ")
print("0. Exit")
ch = int(input("Enter your choice:"))
if ch == 1:
Input()
elif ch == 2:
Read_Record()
elif ch == 3:
Update_Record()
else:
break

RESULT:
The program was executed and output was obtained successfully.

You might also like