Completed

try/except/else/finally - combined exception scenarios

Class 12 · Computer Science Tue, 6 Oct 2026 9:00 PM 60s / question 15 questions · 15 marks

Questions From This Challenge

Q1mcq1 mark
What is the purpose of the else clause in a try-except-else block?
It runs only if an exception occurs in the try block
It runs only if no exception occurs in the try block ✓
It always runs regardless of whether an exception occurred
It replaces the except block entirely
Q2mcq1 mark
What is the purpose of the finally clause in a try-except-finally block?
It runs only when an exception occurs
It runs only when no exception occurs
It always runs, whether or not an exception occurred ✓
It runs only if the else block also runs
Q3mcq1 mark
In a try-except-else-finally block, if an exception occurs in the try block and is caught by except, does the else block execute?
Yes, it always executes
No, else is skipped whenever an exception was raised and caught ✓
Only if finally also runs
Only if the exception is printed
Q4mcq1 mark
Given a try block that raises no exception, in what order do the else and finally blocks execute?
finally runs, then else
else runs, then finally ✓
Only finally runs; else is skipped
Only else runs; finally is skipped
Q5mcq1 mark
If an exception occurs in the try block that is NOT caught by any except clause, does the finally block still execute before the error propagates further?
Yes, finally always executes before the exception propagates ✓
No, finally is skipped since the exception was never handled
Only if an else clause is also present
finally never executes when an exception occurs
Q6mcq1 mark
What is the correct order of clauses when using try, except, else, and finally together in one statement?
try, else, except, finally
try, except, else, finally ✓
try, finally, except, else
try, except, finally, else
Q7output1 mark
What is the output?
try:
    x = 20 / 4
except ZeroDivisionError:
    print("Error")
else:
    print("Success:", x)
finally:
    print("Execution complete")
Correct output: Success: 5.0 Execution complete
Q8output1 mark
What is the output?
try:
    x = 20 / 0
except ZeroDivisionError:
    print("Error occurred")
else:
    print("No error")
finally:
    print("Execution complete")
Correct output: Error occurred Execution complete
Q9output1 mark
What is the output?
data = {"a": 1, "b": 2}
try:
    val = data["c"]
except KeyError:
    print("Missing key")
else:
    print("Found:", val)
finally:
    print("Lookup done")
Correct output: Missing key Lookup done
Q10output1 mark
What is the output?
data = {"a": 1, "b": 2}
try:
    val = data["a"]
except KeyError:
    print("Missing key")
else:
    print("Found:", val)
finally:
    print("Lookup done")
Correct output: Found: 1 Lookup done
Q11output1 mark
What is the output?
nums = [10, 20, 30]
try:
    print(nums[5])
except IndexError:
    print("Index error")
except ZeroDivisionError:
    print("Zero div error")
else:
    print("No problem")
finally:
    print("Cleanup")
Correct output: Index error Cleanup
Q12output1 mark
What is the output?
try:
    total = "Marks: " + 95
except TypeError:
    print("Type error caught")
else:
    print("No error occurred")
finally:
    print("Process ended")
Correct output: Type error caught Process ended
Q13output1 mark
What is the output?
try:
    age = int("17")
except ValueError:
    print("Invalid input")
else:
    print("Age accepted:", age)
finally:
    print("Input check done")
Correct output: Age accepted: 17 Input check done
Q14output1 mark
What is the output?
try:
    print("Start")
    a = 8
    b = 2
    c = a / b
except ZeroDivisionError:
    print("Cannot divide")
else:
    print("Division result:", c)
finally:
    print("Block finished")
print("Outside try")
Correct output: Start Division result: 4.0 Block finished Outside try
Q15output1 mark
What is the output?
try:
    scores = [88, 92]
    print("First score:", scores[0])
    print("Third score:", scores[2])
    print("This will not print")
except IndexError:
    print("Index out of range")
else:
    print("All scores printed")
finally:
    print("Score check complete")
Correct output: First score: 88 Index out of range Score check complete
Next Live Challenge
Mixed: DML + Retrieval - Combined Application
Class 12 · Computer Science Fri, 23 Oct 2026, 9:00 PM
View Live Challenges →

← Back to Live Challenge History · Practice MCQs

CodeBuddy
Hi there! 👋 I'm CodeBuddy, your KV Coders assistant.

To help me give you the most accurate answers, please select your class and subject below, or just type your question!
Buddy is typing...