A : -1/1 = -1.0, no exception is raised. Since no exception occurs, the else block is executed: 1/1 = 1.0.
B : x = 1 runs without any problem. except block is skipped. else block runs: x = x + 2 = 3.
C : y is undefined, so x = y + 1 raises NameError. Handled by except (NameError, SystemError). But then x = y + 1 again runs inside the except block — still y is undefined!
D : 1 / 0 raises a ZeroDivisionError, not a NameError. So the except NameError: block does not catch it.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
herrmann69
Highly Voted 1 year, 2 months agoAbbribas
Most Recent 1 month, 3 weeks agoDave304409
1 year, 1 month agoDKAT2023
1 year, 1 month agoNikhil_Durgesh
1 year, 2 months agokstr
1 year, 2 months agoa4129fd
1 year, 2 months ago