easy +10 pts

Next Weekday Finder

Given a date, return the date of the next weekday (Mon-Fri) after it.

Write a function `next_weekday(date_str)` that takes a string representing a date in `YYYY-MM-DD` format and returns the date of the next weekday (Monday to Friday) strictly after that date, in the same format. Weekends are Saturday and Sunday. The input date is always valid. For example, if the input is `2024-03-08` (a Friday), the next weekday is the following Monday `2024-03-11`. If the input is `2024-03-04` (a Monday), the next weekday is Tuesday `2024-03-05`. Use the standard Python `datetime` module. The output string must be in `YYYY-MM-DD` format.

Constraints

Input is a valid date in `YYYY-MM-DD` format. The date is between year 1 and 9999 inclusive. Performance: O(1) time.

Example

>>> next_weekday('2024-03-08')
'2024-03-11'
>>> next_weekday('2024-03-04')
'2024-03-05'
>>> next_weekday('2024-03-09')
'2024-03-11'
10 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Parse the input string into a date object using `date.fromisoformat()`.
Add one day repeatedly until the weekday is less than 5 (Monday=0, Sunday=6).
Return the resulting date formatted with `isoformat()`.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.