Answer is C.)
Simply, because there's no code inside the try block that raises an exception, the except block is not executed, and the code continues to print "3" after executing the try block.
@clcoding Answer: C
Solution: If we understand the try-except structure, we can easily solve this question.
So let's get into:
1. What try-except is for
2. How try-except works
3. Getting the answer for this code snippet
Ready?
+
@clcoding C) 1 3
Let’s briefly explain the try except in Python.
In Python, `try` and `except` are used to handle errors or exceptions in your code. Think of it like this: when your code is running and encounters a problem
+
@clcoding 1 3. No condition is given so Python considers it as Truthy and executes try block, printing 1. Then last line which is outside try & except block is executed, printing 3. Thus output is. 1 3 on separate lines.
@clcoding c)1 3
Now talking about the 'Try' and 'Except' is used to handle error so using except will make sure not to print 2. So 1 and 3 are printed.
@clcoding Output: 1 3
First try block will run, and since there would be no error so the except block will be skipped, and the last print statement will always run.