← Back to challenges

Day Number of Year

PythonHarddatesformattingnumbersstrings

Instructions

Each year has 365 or 366 days. Given a string date representing a Gregorian calendar date formatted as month/day/year, return the day-number of the year.

Examples

day_of_year("11/16/2020") ➞ 321

day_of_year("1/9/2019") ➞ 9

day_of_year("3/1/2004") ➞ 61

day_of_year("12/31/2000") ➞ 366

Notes

All input strings in tests are valid dates.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.