0% found this document useful (0 votes)
21 views4 pages

Import Pickle

The document contains a Python script that manages student records using the pickle module for serialization. It includes functions for writing records, reading them, searching for a specific record, and finding the maximum and minimum marks. Additionally, it allows for updating a student's marks based on their roll number.
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)
21 views4 pages

Import Pickle

The document contains a Python script that manages student records using the pickle module for serialization. It includes functions for writing records, reading them, searching for a specific record, and finding the maximum and minimum marks. Additionally, it allows for updating a student's marks based on their roll number.
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
You are on page 1/ 4

import pickle

def writing():

f=open("mylist.dat","wb")

record=[]

while True:

name=input("Enter name")

roll=int(input("Enter Roll number"))

marks=int(input("Enter marks"))

data=[roll,name,marks]

record.append(data)

choice=int(input("\n1Enter more values\n2Exit\nEnter your choice"))

if choice==2:

break

pickle.dump(record,f)

f.close()

writing()

def reading():

f=open("mylist.dat","rb")

data=pickle.load(f)

print(data)

f.close()

reading()
def searching():

f=open("mylist.dat","rb")

data=pickle.load(f)

target=input("Enter the name of record you want to search")

for i in data:

flag=0

if i[1]==target:

print(i)

flag=1

break

if flag==0:

print("Sorry no record found")

f.close()

searching()

def maximum():

f=open("mylist.dat","rb")

data=pickle.load(f)

maxm=data[0][2]

for i in data:

if i[2]>=maxm:

maxm=i[2]

z=i

print("Maximum marks are ",z)

f.close()
maximum()

def minimum():

f=open("mylist.dat","rb")

data=pickle.load(f)

minm=data[0][2]

for i in data:

if i[2]<=minm:

minm=i[2]

z=i

print("Minimum marks are ",z)

f.close()

minimum()

def updating():

f=open("mylist.dat","rb+")

data=pickle.load(f)

target=int(input("Enter roll number whose marks needs to be updated"))

job=int(input("Enter the new marks"))

flag=0

for i in data:

if i[0]==target:

i[2]=job
pickle.dump(data,f)

print(i)

print("Data Updated Successfully")

flag+=1

break

if flag==0:

print("Sorry, no record found")

f.close()

updating()

You might also like