11. What is the purpose of the assert statement in Python?
12. The following Python code will result in an error if the input value is entered as -5.
assert False, 'Spanish'
assert False, 'Spanish'
13. What is the purpose of the except clause in a try block?
14. What is the output of the following code:
try:
x = 10 / 0
except ZeroDivisionError:
print("Error!")
finally:
print("Finally!")
try:
x = 10 / 0
except ZeroDivisionError:
print("Error!")
finally:
print("Finally!")
15. Which of the following is not an exception handling keyword in Python?
16. What is the purpose of the else clause in a try block?
17. What is the purpose of the finally clause in a try block?
18. How can you create a custom exception class in Python?
19. What is the syntax to raise an exception manually in Python?
20. What will be the output of the following Python code?
def getMonth(m):
if m<1 or m>12:
raise ValueError("Invalid")
print(m)
getMonth(6)
def getMonth(m):
if m<1 or m>12:
raise ValueError("Invalid")
print(m)
getMonth(6)