Python Try / Except Exercises

Let’s check out some exercises that will help understand Try / Except better.

Exercise 3-a: ZeroDivisionError Exception w/ Try Except Statements

Place result="You can't divide with 0" to the right place so that program avoids ZeroDivisionError.


Since except ZeroDivision is already there:

simply place the value assignment for result after Except line.

Pay attention to indentations.

    result="You can't divide with 0"

Exercise 3-b: pass statement inside Try Except Statements

.get() is not a list method. Place pass keyword to the right line so that program doesn't throw an error.


All you have to do is type pass on the right line with the right indentation.

Watch out for when you use except and pass statements like this as they are pretty generalist statements and can cause trouble in more complex programs.

    pass