avatar Bite 10. Practice exceptions

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!

Login and get coding
go back Intermediate level
Bitecoin 3X

343 out of 349 users completed this Bite.
Will you be Pythonista #344 to crack this Bite?
Resolution time: ~26 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 3.0 on a 1-10 difficulty scale.
» You can do it! 😌

We use Python 3.8