Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is the purpose of the try block in Python?

View

What will be the output of this code? try: print(1 / 0) except ZeroDivisionError: print("Error")

View

What does the finally block do?

View

What will be the output of this code? try: print("Hello"); raise Exception("Something went wrong") except Exception as e: print(e)

View

Which of the following will NOT raise an exception?

View

What is the correct syntax for catching multiple exceptions?

View

What will happen if you do not handle an exception?

View

What is the output of this code? try: print("Hi"); raise ValueError("An error occurred"); finally: print("Done")

View

What type of exception will this code raise? print(1 + "2")

View

How can you define a custom exception in Python?

View

What is the purpose of the try block in Python?

To execute code that may raise an exception
To define a function
To create a loop
None of the above

What will be the output of this code? try: print(1 / 0) except ZeroDivisionError: print("Error")

1
0
Error
Error

What does the finally block do?

It runs only if there is an exception.
It runs regardless of whether an exception occurred.
It can only be used with try.
None of the above.

What will be the output of this code? try: print("Hello"); raise Exception("Something went wrong") except Exception as e: print(e)

Hello
Error
Something went wrong
None of the above

Which of the following will NOT raise an exception?

int("abc")
print(1 / 0)
print("Hello")
len(5)

What is the correct syntax for catching multiple exceptions?

except (ValueError, TypeError):
except ValueError, TypeError:
except ValueError or TypeError:
except ValueError; TypeError:

What will happen if you do not handle an exception?

The program will continue without interruption.
The program will terminate.
A warning will be issued.
The exception will be logged.

What is the output of this code? try: print("Hi"); raise ValueError("An error occurred"); finally: print("Done")

Hi Done
Hi
Done
Error

What type of exception will this code raise? print(1 + "2")

ValueError
TypeError
SyntaxError
NameError

How can you define a custom exception in Python?

class MyException(Exception): pass
def MyException(): pass
raise MyException
MyException = Exception