Login and get codingIn this Bite, you build a function that tells you how far ahead or behind an annual goal you are. This could be a New Year's Resolution (you are still on track, right?). You can use the code you build to check in often and track your progress.
For this Bite a goal can be expressed as a number, like the number of steps you want to walk in a year, or the number of times you substitute a healthy snack for junk food in a year. The function arguments are:
- a string (the description of the goal)
- the target for the year as an integer or a calculation like
(30 * 365)
- your current score
- a
tuple
with (year, month, day) for the date you achieved the current scoreThe function returns a message that varies depending on whether you are on track to achieve the goal at the end of the year given your pace so far.
If the tuple representing the date is not a valid date, the function could raise a
ValueError
or aTypeError
. Your solution does not need to check for these errors.I encourage you to use tuple unpacking to populate a date from the date tuple passed in.
The
return
statement should be carefully formatted to exactly match the examples below.Note: if you are exactly on track, the function returns a congratulations message, saying that you are 0 ahead!
HINT: In honour of this being Bite 366, we want you to take leap days into account (for years with 366 days).
If either of the final 2 tests fail (goals for "leaps" and "jumps"), consider whether you adjusted the target per day.
Remember also to include the current day in the number of elapsed days in the year. So January 1 = 1 day, NOT 0 days!
Examples
>>> from goal_tracker import goal_tracker
>>> goal_tracker("days of code", 365, 13, (2023, 1, 5))
'Congratulations! You are on track with your days of code goal. The target for 2023-01-05 is 5 days of code and you are 8 ahead.'
>>> goal_tracker("pages read", 36500, 27298, (2023, 9, 30))
'You have some catching up to do! The target for 2023-09-30 is 27,300 pages read and you are 2 behind.'Keep calm and code in Python!
14 out of 14 users completed this Bite.
Will you be the 15th person to crack this Bite?
Resolution time: ~78 min. (avg. submissions of 5-240 min.)