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

Question 2

The document contains a Python script that implements a menu-driven program for managing student details stored in a binary file using pickle. It allows users to write new student records, read existing records, and update marks for a specific student based on their roll number. The program continues to prompt the user for actions until they choose to exit.

Uploaded by

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

Question 2

The document contains a Python script that implements a menu-driven program for managing student details stored in a binary file using pickle. It allows users to write new student records, read existing records, and update marks for a specific student based on their roll number. The program continues to prompt the user for actions until they choose to exit.

Uploaded by

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

#Write a python menu driven code to perform write, read and update operations on

[Link]
import pickle
def Write():
f=open('[Link]','ab')
ans='y'
while ans=='y':
rno=input('Enter Roll Number:')
name=input('Enter Name:')
marks=input('Enter Marks:')
st=[rno,name,marks]
[Link](st, f)
ans=input('Want to add more records?(y/n):')
[Link]()

def Read():
f=open('[Link]','rb')
while True:
try:
st=[Link](f)
print(st)
except EOFError:
break
[Link]()

def Update(r,m):
f=open('[Link]','rb+')
try:
while True:
pos=[Link]()
st=[Link](f)
if st[0]==r:
st[2]=m
[Link](pos)
[Link](st,f)
break
except Exception:
[Link]()

while True:
print('BINARY OPERATIONS')
print('1. Write')
print('2. Read')
print('3. Update')
print('4. Exit')
ch=int(input('Enter Choice:'))
if ch==1:
Write()
elif ch==2:
Read()
elif ch==3:
rn=input('Enter roll number to be updated:')
m=input('New marks')
Update(rn, m)
elif ch==4:
break
else:
print('Invalid choice')
OUTPUT:

You might also like