Bite 186. Calculate number of books to have read at date ...

For this Bite you are asked to start working on a reading goal feature for PyBites My Reading List.

Code up get_number_books_read that takes a yearly # books to read int and then calculates the amount of books user should have read based on the at_date argument which defaults to NOW. So if the goal is 52, and we call this function week 11, it should return 11. If the goal is 100 and we call this function in week 47 the function should return 90 (47/52*100), rounding to int. Some more examples:

>>> get_number_books_read(100, 'Sunday, March 25th, 2019')
25
>>> get_number_books_read(52, 'Sunday, March 18th, 2019')
12
>>> get_number_books_read(52, '5-20-2018')
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/bbelderbos/code/bitesofpy/186/books.py", line 20, in get_number_books_read
    raise ValueError('Should have positive goal and future date')
ValueError: Should have positive goal and future date

Check the docstring, comments and tests for more guidance. Keep calm and code in Python!

16 out of 17 users completed this Bite.
Will you be Pythonista #17 to crack this Bite?
It takes an average of ~56 minutes to solve this Bite (submissions 5-240 min).
Pythonistas rate this Bite 2.0 on a 1-10 difficulty scale.
» You can do it! 😌

Login and get coding
We use Python 3.7