Exception Handling in Python · Class 12 · CBSE · Science Computer Science

What will be the output of the following Python code? try: value = int("10") except ValueError: print("invalid") else: print(value / 4) finally: prin…

Practice question from Exception Handling in Python (Class 12 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

medium · MCQ · Q-F79368

What will be the output of the following Python code? try: value = int("10") except ValueError: print("invalid") else: print(value / 4) finally: print("finished")

  1. A.invalid finished
  2. B.2.5 finishedCorrect answer
  3. C.2 finished
  4. D.finished

Solution

The string "10" is successfully converted to an integer, so the except block is skipped and the else block prints 2.5. The finally block then prints finished.

More from Exception Handling in Python

All of Exception Handling in Python

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed