Class - 12 CBSE Computer Science Important File Handling Questions 2025
Anant has been asked to display all the students who have scored less than 40 for Remedial Classes. Write a user-defined function to display all those students who have scored less than 40 from the binary file "Student.dat".
Python Data Handling
1 Like
Answer
Let the file "Student.dat" include the following sample data:
Radhika 80
Shaurya 35
Sonia 38
Anirudh 45
import pickle
def display_students(file_name):
file = open(file_name, 'rb')
students = pickle.load(file)
for student in students:
name = student[0]
score = student[1]
if score < 40:
print(name)
file.close()
display_students('student.dat')
Output
Shaurya
Sonia
Answered By
1 Like