0% found this document useful (0 votes)
2 views

practical

The document contains a Python script for managing student records using the pickle module for serialization. It includes functions to add, display, and search for student records based on roll number. The script runs a menu-driven interface allowing users to perform these operations until they choose to exit.

Uploaded by

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

practical

The document contains a Python script for managing student records using the pickle module for serialization. It includes functions to add, display, and search for student records based on roll number. The script runs a menu-driven interface allowing users to perform these operations until they choose to exit.

Uploaded by

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

import pickle

def Addrec():
data=[]
rno=int(input("enter the rollno"))
name=input("enter the name")
marks=int(input("enter the marks"))
rec={"rollno":rno,"name":name,"marks": marks}
f=open("student1.dat","ab")
pickle.dump(rec,f)
f.close()

def Displayrec():
f=open("student1.dat","rb")
while True:
try:
rec=pickle.load(f)
print("roll no",rec["rollno"],"name",rec["name"],"marks",rec["marks"])
except EOFError:
break
f.close()

def Searchrec(r):
f=open("student1.dat","rb")
flag=False
while True:
try:
rec=pickle.load(f)
if rec['rollno']==r:
print("roll
no",rec["rollno"],"name",rec["name"],"marks",rec["marks"])
flag=True
except EOFError:
break
if flag==False:
print("no record found")
f.close()

while True:
print("Menu")
print("1. Enter 1 to Add a new student")
print("2. Enter 2 to Show all students")
print("3. Enter 3 to Search a student")
print("4. Enter 4 to Exit")
ch=int(input("enter your choice"))
if ch==1:
Addrec()
elif ch==2:
Displayrec()
elif ch==3:
r=int(input("enter the rollno to be searched"))
Searchrec(r)
elif ch==4:
break

You might also like