The following Python function is designed to remove the records of students…

PYQ EMRS TGT/PGT (ESSE) 2025

The following Python function is designed to remove the records of students who scored less than 33 marks from a CSV file named result.csv. The file contains data in the format RollNo, Marks. To achieve this, the function reads all valid records into a list and then overwrites the original file with only those students who have passed (Marks ≥ 33).

import csv

def delete_failing_students():
    passed_students = []
    try:
        with open( ______ (A) ______ ) as File:
            reader_obj = ______ (B) ______
            for row in reader_obj:
                if int(row[1]) >= 33:
                    passed_students.append(row)

            File.seek(0)
            Writer_obj = ______ (C) ______
            Writer_obj. ______ (D) ______
            File.truncate()

    except FileNotFoundError:
        print("File not found.")

Questions:

(A) Write the arguments including newline inside the open() function for Blank A to open the CSV file for reading as well as writing purposes.

(B) Write the method call for Blank B to create an object that can read the lines of the CSV file.

(C) Provide the method call for Blank C to create an object used to write data into the CSV file.

(D) Provide the method call for Blank D to write the content of the Python list passed_students into the CSV file.

Attempted by 59 students.

Sign up free to check your answer

Sign up free

Explore the full course: Emrs Cs Tier 2

Loading lesson…