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

PCAP-31-03 Exam - Question 45


What is the expected behavior of the following code?

Show Answer
Correct Answer: D

The code attempts to convert the string '2A' to an integer using the int() function. Since '2A' is not a valid integer, this conversion raises a ValueError. The code has an except block specifically for ValueError, which sets n to 2. Therefore, the correct output is 2.

Discussion

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

D is correct