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. #Type your answer below (pick the correct line). a=5 b=0 try: result=a/b except ZeroDivisionError: print(result) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(result,"You can't divide with 0","result checks") myTests().main() Hint 1 Since except ZeroDivision is already there:simply place the value assignment for result after Except line. Hint 2 Pay attention to indentations. Solution 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. #Type your code here. a = [1, 3, 5] try: a.get() except: print(a) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(a,[1, 3, 5],"a checks") myTests().main() Hint 1 All you have to do is type pass on the right line with the right indentation. Hint 2 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. Solution pass Exercise 3-c: except Exception w/ Try Except Statements Place msg="You can't add int to string" to the right place so that program avoids BaseExceptionError. You can use except Exception although normally you should be careful using such powerful exception statements. #Type your answer below. a="Hello World!" try: a + 10 print(msg) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(msg,"You can't add int to string","msg checks") myTests().main() Hint 1 Just assign the right message to msg on the right line. Solution except Exception: msg="You can't add int to string" Exercise 3-d: IndexError w/ Try Except Statements Place msg="You're out of list range" to avoid IndexError. #Type your answer below. lst=[5, 10, 20] try: print(lst[5]) print(msg) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(msg,"You're out of list range","msg checks") myTests().main() Hint 1 Just assign the right message to msg on the right line. Solution except IndexError as error: msg="You're out of list range"