+ 2
Why is the print statement of print (hello) missed in this code
try: print(1 / 0) print("Hello") except ZeroDivisionError: print("Divided by zero") finally: print("This code will run no matter what")
3 odpowiedzi
+ 2
Thank you Faisal
+ 2
Because you put print("hello") in try block which raises ZeroDivisionError and jump to catch block.
+ 1
Because 1 ÷ 0 raises the ZeroDivisonError and the print statement that outputs hello is after the print that raises the error, once the error is raised, everything else within the try statement gets skipped over as the code will jump straight to the except statement. For "Hello" to be printed, it would need to appear before the first print to avoid getting it ignored.