Completed

Exception Basics - try/except introduction

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

Questions From This Challenge

Q1mcq1 mark
What is the primary purpose of a try-except block in Python?
To make the program run faster
To handle runtime errors gracefully without crashing the program ✓
To declare variables before they are used
To define a new function
Q2mcq1 mark
Which exception is raised when a program attempts to divide a number by zero, e.g. `10 / 0`?
ValueError
ZeroDivisionError ✓
TypeError
IndexError
Q3mcq1 mark
Which exception is raised by the following code? num = int("seven")
TypeError
KeyError
ValueError ✓
IndexError
Q4mcq1 mark
Which exception is raised by the following code? marks = [70, 80, 90] print(marks[10])
IndexError ✓
KeyError
ValueError
TypeError
Q5mcq1 mark
Which exception is raised by the following code? student = {"name": "Riya"} print(student["grade"])
IndexError
ValueError
KeyError ✓
TypeError
Q6mcq1 mark
Which exception is raised by the following code? result = "Total: " + 100
ValueError
IndexError
KeyError
TypeError ✓
Q7mcq1 mark
In a try-except block, if no exception occurs while executing the try block, what happens to the except block?
It executes anyway after the try block
It is skipped entirely ✓
It raises a SyntaxError
The program terminates immediately
Q8mcq1 mark
Consider: try: print("A") print(10 / 0) print("B") except ZeroDivisionError: print("C") Which lines are actually printed?
A, B, C
A, C ✓
A, B
C only
Q9output1 mark
What is the output?
try:
    x = 10 / 0
except ZeroDivisionError:
    print("Cannot divide by zero")
Correct output: Cannot divide by zero
Q10output1 mark
What is the output?
try:
    a = [1, 2, 3]
    print(a[5])
except IndexError:
    print("Index out of range")
print("Program continues")
Correct output: Index out of range Program continues
Q11output1 mark
What is the output?
d = {"name": "Amit", "age": 17}
try:
    print(d["marks"])
except KeyError:
    print("Key not found")
Correct output: Key not found
Q12output1 mark
What is the output?
try:
    num = int("25a")
    print(num)
except ValueError:
    print("Invalid number")
print("Done")
Correct output: Invalid number Done
Q13output1 mark
What is the output?
try:
    result = "5" + 5
    print(result)
except TypeError:
    print("Type mismatch")
Correct output: Type mismatch
Q14output1 mark
What is the output?
try:
    marks = [90, 85, 78]
    print(marks[1])
    print(10 / 0)
except IndexError:
    print("Index problem")
except ZeroDivisionError:
    print("Division problem")
Correct output: 85 Division problem
Q15output1 mark
What is the output?
try:
    x = 15
    y = 3
    print(x // y)
except ZeroDivisionError:
    print("Cannot divide")
print("End")
Correct output: 5 End
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...