Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
The function test(value) has a try that does 10 // value, an except for ZeroDivisionError, an else and a finally. What does the program show for test(5) and for test(0)?
else runs when there is no error. finally always runs.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
For test(5). The division works and gives 2, so the try part shows try: 2. There was no error, so else runs. Then finally always runs.
try: 2, else, finally.
For test(0). The division fails with a ZeroDivisionError. The except part runs. else is skipped, because there was an error. finally still runs.
except, finally.
Log in to join the discussion.
Loading…