easy +8 pts

Week Number ISO

Compute the ISO 8601 week number for any given date.

Implement a function `iso_week_number(year, month, day)` that returns the ISO 8601 week number for the given date as an integer (1–53). The ISO week number is defined as follows: - Weeks start on Monday. - Week 1 of a year is the week that contains the first Thursday of that year. - The resulting week number can be between 1 and 53. Your implementation must compute the week number manually using date arithmetic; you may **not** use `datetime.isocalendar()` or any equivalent library method (e.g., `date.isocalendar()`). Use only Python's standard library `datetime` and `timedelta` for calendar calculations. The input will always be a valid Gregorian calendar date.

Constraints

- 1 ≤ year ≤ 9999 - 1 ≤ month ≤ 12 - 1 ≤ day ≤ 31 for the given month - Time complexity: O(1) - Do not use `isocalendar()` or similar.

Example

>>> iso_week_number(2024, 1, 1)
1
>>> iso_week_number(2020, 12, 31)
53
>>> iso_week_number(2021, 1, 1)
53
>>> iso_week_number(2023, 5, 17)
20
8 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Remember that ISO years can differ from calendar years; early January may belong to the previous ISO year.
Consider using the Thursday of the week containing your date to determine the ISO week number.
To find the week number, compare your date's Thursday to the Thursday of the first week of the ISO year.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.