Question:medium

Consider the following code and specify the correct order of the statements to be written:
Code:
(A) f.write(”CUET EXAMINATION”)
(B) f=open(”CUET.TXT”, ”w”)
(C) print(”Data is Written Successfully”)
(D) f.close()
Choose the correct answer from the options given below:

Updated On: Jan 16, 2026
  • (A), (B), (C), (D)
  • (B), (A), (C), (D)
  • (B), (D), (C), (A)
  • (B), (D), (A), (C)
Show Solution

The Correct Option is B

Solution and Explanation

To correctly order statements for Python file operations, follow this sequence: open the file, perform operations (e.g., writing), optionally provide feedback, and finally close the file. Detailed steps:

  1. Open File: Use open() to create or open a file for writing. This initializes the file handler (f) for subsequent use.
  2. Write to File: Employ the write() method after opening to insert data into the file.
  3. Display Status: After writing, a success message can be printed to confirm the operation's completion.
  4. Close File: Execute close() to securely terminate the file operation, freeing resources and ensuring data is saved.

Applying this order to the provided options yields:

  • (B) f=open("CUET.TXT", "w"): Corresponds to Step 1, file opening for writing.
  • (A) f.write("CUET EXAMINATION"): Corresponds to Step 2, writing the specified string.
  • (C) print("Data is Written Successfully"): Corresponds to Step 3, outputting a success notification.
  • (D) f.close(): Corresponds to Step 4, file closure.

Therefore, the correct sequence of statements is:

(B), (A), (C), (D)
Was this answer helpful?
0