Return to Dashboard

Module 25: Exception Handling Check

Question 1

What is the primary purpose of using a try...except block in Python?

Question 2

Consider the following code:
try:
  result = 10 / 0
except ZeroDivisionError:
  print("Cannot divide by zero!")

What will be printed?

Question 3

Which keyword is used to specify a block of code that will always execute, regardless of whether an error occurred in the `try` block or not (assuming it's present)?

Question 4

If you want to catch a specific type of error, like a ValueError, how should you write the `except` block?

Question 5

What happens if an error occurs inside a `try` block, but there is no corresponding `except` block to handle that specific type of error (and no general `except` block)?

Question 6

Consider this code:
try:
  num = int(input("Enter a number: "))
  print("You entered:", num)
except ValueError:
  print("Invalid input!")

What will happen if the user enters the text "hello"?

Question 7

Which built-in Python exception is typically raised when you try to open a file that does not exist in read mode ('r')?

Question 8

What is the main benefit of handling exceptions rather than letting the program crash?

Question 9

How can you handle multiple specific exceptions with the same block of code?

Question 10

If no error occurs in the `try` block, what happens with the `except` block?

Quiz Results

Your Score: 0 / 10

Let's see how you did!