Python Python Basics Functions and Looping Exception Flow

mohan Abdul
PRO
mohan Abdul
Pro Student 1,453 Points

exceptions task 2 why the answer is

can anyone explain why the answer is "ADF" for the flowing script. """print("A") try: result = "test" + 5 print("B") except ValueError: print("C") except TypeError: print("D") else: print("E") print("F")"""

I can't explain it.

1 Answer

Steven Parker
Steven Parker
203,151 Points

Trying to add a string and a number together causes a TypeError, so the try/except group produces a "D" in the output.

The "A" at the beginning and the "F" at the end are both unconditional, so the total output is "A", "D" and "F" (on separate lines).