Question: Catching a ZeroDivisionError There is a function foo ( n ) that takes an integer n does some calculations that involve divisions. Sadly, the people
Catching a ZeroDivisionError
There is a function foon that takes an integer n does some calculations that involve divisions. Sadly, the people who wrote foo sometime divide by zero. This means the code sometimes throws a ZeroDivisionError.
Write a function called safeFoon that runs foon If it runs successfully, it should return whatever foo returned. If it raises a ZeroDivisionError, it should return If it raises any other kind of error, it should return None.
A sample Python run might look like this:
foo # This time it works
foo # This time it divides by zero
Traceback most recent call last:
File line in
ZeroDivisionError
foo # This time it has a Key Error
Traceback most recent call last:
File line in
KeyError x
safeFoo
safeFoo
safeFoo
None
Your code snippet should define the following variables:
Name Type Description
safeFoo function A function that safely calles foo
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
