12.8 CBSE Board Exams: File Handling Questions (Last 5 Years)

 Important Note: The exact wording and numerical values in your actual exam might vary, but the core concepts and required programming logic to solve these problems remain consistent. Practice these questions diligently to ace this section!

Previous Year Questions (Last 5 Years)

Year 2024 (Expected/Sample Questions based on recent patterns)

  1. Write a Python function countWords(filepath) that takes the path of a text file as an argument and returns the total number of words in the file. Assume words are separated by spaces.

  2. Explain the difference between w and a modes for opening a text file in Python.

  3. A binary file student.dat stores student records as a list [RollNo, Name, Marks]. Write a Python function displayAboveMarks(min_marks) that reads the student.dat file and displays the details of all students who scored more than min_marks.

Year 2023

  1. Write a Python program to count the number of lines in a text file NOTES.TXT that do not start with a vowel (A, E, I, O, U).

  2. Differentiate between text file and binary file based on their data storage.

  3. Write a Python function createCSVFile(filename) to create a CSV file named Students.csv and write the following data into it:

    RollNo, Name, Grade
    1, Amit, A
    2, Priya, B
    3, Rohan, A
    

Year 2022

  1. A text file REPORT.TXT contains some text. Write a function countOccurrences(word) that accepts a word as an argument and counts the number of times this word appears in the REPORT.TXT file (case-insensitive).

  2. What is the purpose of the seek() and tell() Methods in file handling?

  3. A binary file PRODUCT.DAT stores product information as a dictionary {'PCode': 'P001', 'PName': 'Laptop', 'Price': 85000}. Write a Python function updatePrice(PCode, new_price) that takes a product code and a new price, and updates the price of that product in the PRODUCT.DAT file.

Year 2021

  1. Write a Python function readReverse(filename) that reads a text file DATA.TXT and displays its content in reverse order (character by character, not line by line).

  2. What is the significance of newline='' opening a CSV file in Python?

  3. Consider a CSV file Marks.csv with data like: RollNo,Subject,Marks. Write a Python function countStudentsFailed(subject_name) that counts and returns the number of students who scored less than 33 marks in the given subject_name.

Year 2020

  1. Write a Python function displayLongestWord(filename) that reads a text file STORY.TXT and displays the longest word present in the file. If there are multiple words of the same maximum length, display any one of them.

  2. Give an example of how to write a Python list my_list = [10, 20, 30] into a binary file numbers.dat.

  3. Write a Python function searchStudent(roll_no) to search for a student by their roll_no in a CSV file students.csv. If found, display their details; otherwise, print "Student not found." The file has columns: RollNo,Name,Class.

Previous Post Next Post