PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 65


What is the expected output of the following code if existing_file is the name of a file located inside the working directory?

Show Answer
Correct Answer: C

The code attempts to open a file named 'existing file' in write mode. If the file opens successfully, it will execute the code within the try block, printing '1' and then moving to the else block where it will close the file and print '3'. Since there is no error in opening the file, the except block is not executed. Therefore, the output will be '1 3'.

Discussion

1 comment
Sign in to comment
DKAT2023Option: C
Jul 12, 2024

C is correct