We use Python 3.6

go back Level: Intermediate (img: IM / score: 3) level Bite 10. Practice exceptions

44 out of 44 users completed this Bite ...
Will you be Pythonista #45 to crack this Bite?
Average Bite difficulty 1-10 rating: 3.33
» You can do it! 😌

In this bite you learn to catch/raise exceptions.

Write a simple division function meeting the following requirements:

  1. when denominator is 0 catch the corresponding exception and return 0.
  2. when numerator or denominator are not of the right type reraise the corresponding exception.
  3. if the result of the division (after surviving the exceptions) is negative, raise a ValueError

As always see the tests written in pytest to see what your code need to pass. Have fun!

Github login button