Indian Institute of Technology Madras
BS Degree Programme · Examination & Study Paper
Programming in Python
Exception handling
Examination Instructions & Guidelines
- Solve on notebook/paper first before checking solutions.
- MCQ: Exactly 1 option is correct. Negative marking applies.
- MSQ: One or more options correct. Select all to score.
- NAT: Numerical response. No negative marking.
- Scientific calculator allowed for all calculations.
- Official answer key is sealed at the end of this sheet.
End Term · 31 Aug 2025 (FN)End Term
- Q1MSQ3 Marks·Choose all correct options
Which of the following statements about the exception handling behavior are TRUE? Select ALL that apply. def safe_divide(x, y): result = [] try: result.append("Trying division") result.append(x // y) except ZeroDivisionError: result.append("Division by zero") else: result.append("No exception occurred") finally: result.append("Cleanup done") return result output = safe_divide(10, 0) print(output)
- AThe output will contain the string _("Trying division")
- BThe string _("Division by zero") will appear in the output
- CThe division result will be appended to the output
- DThe string _("Cleanup done") will always appear regardless of exceptions
End Term · 31 Aug 2025 (AN)End Term
- Q2MCQ3 Marks·Choose one option
Given the following code snippet, what will be the output? def get_square(items, i): return items[i]**2 def safe_get_square(items,i): try: return get_square(items,i) except IndexError: return 0 except: return -1 nums = [5, -2, 3] print(safe_get_square(nums , 1)) print(safe_get_square(nums , -1)) print(safe_get_square([] , -1)) print(safe_get_square(None , 1))
- A25 0 -1 -1
- B4 4 -1 -1
- C4 9 -1 -1
- D4 9 0 -1
End Term · 22 Dec 2024 (FN)End Term
- Q3NAT3 Marks·Write the number
Your answer:
End Term · 22 Dec 2024 (AN)End Term
- Q4NAT3 Marks·Write the number
Your answer: