What is the expected behavior of the following program?
try:
print(5/0)
break
except:
print("Sorry, something went wrong…")
except (ValueError, ZeroDivisionError):
print("Too bad…")
A . The program will cause a SyntaxError exception.
B. The program will cause a ValueError exception and output the following message: Too bad…
C. The program will cause a ValueError exception and output a default error message.
D. The program will raise an exception handled by the first except block.
E. The program will cause a ZeroDivisionError exception and output a default error message.
Answer: A
Explanation:
Topics: try except break SyntaxError ValueError
ZeroDivisionError
Try it yourself:
try:
print(5/0)
# break except:
print("Sorry, something went wrong…")
# except (ValueError, ZeroDivisionError):
# print("Too bad…")
There are two syntax errors:
break can not be used outside of a loop,
and the default except must be last.
Latest PCEP-30-02 Dumps Valid Version with 124 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund