Quiz Space

Programming in Python · End Term · 31 Aug 2025 · May 2025 term · Set QDF1

Question 8: Which of the following statements about the exception han…

Question 8

+3 marksOne or more 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)

Select all that apply.

  1. A

    The output will contain the string "Trying division"

  2. B

    The string "Division by zero" will appear in the output

  3. C

    The division result will be appended to the output

  4. D

    The string "Cleanup done" will always appear regardless of exceptions

Show answer

Correct answers

  • A

    The output will contain the string "Trying division"

  • B

    The string "Division by zero" will appear in the output

  • D

    The string "Cleanup done" will always appear regardless of exceptions

Question 8 of 20 in the IIT Madras BS Programming in Python (Python) End Term paper sat on 31 Aug 2025, in the May 2025 term (IIT M FOUNDATION AN EXAM QDF3 31 Aug 2025). It carries 3 marks.

More questions from this paper

  1. Q1What will be the output of the following Python code?\ words = ["jacket", "cap", "scarf", "hat", "sock"]\ result = []\ …
  2. Q2Consider the following Python code:\ def evaluate_score(score):\ if score >= 90:\ if score == 100:\ print("Perfect Scor…
  3. Q3Consider the following Python code:\ class Employee:\ def init(self, name):\ self.name = name\ self.role = "Employee"\ …
  4. Q4What will be the total number of lines printed when the following code is executed? scores = {\ "Aarav": [10, 20, 30],\…
  5. Q5What will be the output of the following code snippet?\ data = [(4, 7), (5, 8), (6, 6), (9, 3)]\ total = 0\ for a, b in…
  6. Q6What will be the output of the following code?\ items = ["apple", "banana", "cherry", "date", "fig", "grape", "kiwi"]\ …
  7. Q7Consider the use of the map() function in the following code snippets. Select all options that has the value [4, 9, 16,…
  8. Q9Consider the following code snippet:\ def update_scores(scores, bonus):\ updated = []\ for score in scores:\ updated.ap…
  9. Q10Consider the following Python code:\ names = ["Aarav", "Bhuvan", "Charan", "Deepa"]\ marks = [88, 76, 92, 81]\ bonus = …
  10. Q11Consider the following Python code:\ with open("data.txt", "w") as f:\ for i in range(3):\ for j in range(i + 1):\ f.wr…
  11. Q12Consider the following Python code:\ a1 = (3, 6, 9, 12, 15, 18, 21, 24)\ a2 = a1[2:7]\ a3 = a2[::-1]\ a4 = tuple(x for …
  12. Q13Consider the following Python code:\ def transform(words):\ if not words:\ return []\ first = words[0][::-1]\ if first …
  13. Q14Consider the following Python code snippet:\ colors = ['red', 'blue', 'green', 'red', 'blue', 'red', 'yellow']\ freq = …
  14. Q15Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  15. Q16Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  16. Q17Consider the following Python code and answer the sub-questions:\ students = [\ {\ "name": "Arya",\ "subjects": {\ "Mat…
  17. Q18Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …
  18. Q19Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …
  19. Q20Consider the following Python code and answer the sub-questions:\ class Vehicle:\ total_vehicles = 0\ all_models = []\ …