Set - 1.pdf
Set - 1.pdf
Date:
Class: 12
Section: A
SET - 01
Practical - 1:
Create a binary file with name and roll number of students. Search for a given roll number
and display the name of student, if not found display appropriate message
#First we import the pickle module to read and write the binary file in Python
import pickle
S={}
while True:
1 SET - 1
print("Press 1: For Add Student")
if choice == 1:
#Use open() for create and open the binary file in append mode
f=open('stud.dat','ab')
S['RollNo']=rno
S['Name']=name
#dump() of pickle module used to write the content in the binary file
pickle.dump(S,f)
f.close()
2 SET - 1
f=open('stud.dat','rb')
K={}
m=0
try:
while True:
K=pickle.load(f)
if K["RollNo"] == rno:
print(K)
m=m+1
except EOFError:
f.close()
if m==0:
else:
break
3 SET - 1
Output:
Press 1: For Add Student
4 SET - 1
Enter the Name of the student: David
5 SET - 1
{'RollNo': 38, 'Name': 'Mohit Mathur'}
Practical - 2:
(a) Display the details of class XII students in descending order of their marks.
(c) Display the city with number of students belongs to that city.
City;
6 SET - 1