Carefully analyze the following Python program. The objective of the program…

PYQ EMRS TGT/PGT (ESSE) 2025

Carefully analyze the following Python program. The objective of the program is to read the complete content of the text file bengal.txt, replace every occurrence of the word “Calcutta” with “Kolkata” and then write the modified content back into the same file. However, certain parts of the program are missing and have been marked as Task A, Task B, Task C and Task D. Complete the missing statements so that the program works correctly without any logical or syntactical errors.

try:
    __________________________ as File:   # Task A

    Text = __________________________     # Task B

    NewText = Text.replace("Calcutta", "Kolkata")

    __________________________ as File:   # Task C

    __________________________             # Task D

except:
    print('File I/O Error!')

(A) Write the missing statement for Task A to open the file in read mode.

(B) Write the missing statement for Task B to read the complete content of the file and store it in the identifier Text.

(C) Write the missing statement for Task C to reopen the file in write mode so that the updated content can be stored.

(D) Write the missing statement for Task D to write the entire modified content stored in NewText into the file.

Attempted by 72 students.

Sign up free to check your answer

Sign up free

Explore the full course: Emrs Cs Tier 2

Loading lesson…