avatar Bite 211. Write a retry decorator

Write a retry decorator that retries executing the function it decorates. If the function raises an exception (any kind) it tries again, until it reaches MAX_RETRIES (set to 3) at which point it throws a MaxRetriesException exception (already defined).

In the tests we define get_two_numbers to test this. It gets a list of numbers which may contain bad data (non ints or floats). It tries to pick 2 random numbers from this list but if both those numbers are not ints, it raises a ValueError in which case the retry decorator would run the function again.

Check out the template's docstring as well as the tests for more details. Good luck and keep calm and code in Python!

Login and get coding
go back Advanced level
Bitecoin 4X

105 out of 106 users completed this Bite.
Will you be Pythonista #106 to crack this Bite?
Resolution time: ~31 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 5.18 on a 1-10 difficulty scale.
» Up for a challenge? 💪

We use Python 3.8