easyUnit 10 · Modules, Exception Handling & File Handling
P29. Days Between Dates
Modules, Exception Handling & File Handling
Use the datetime module (from datetime import date) to work with two dates written as YYYY-MM-DD. Convert them with date.fromisoformat(). If either date is not valid, a ValueError is raised; catch it and print Invalid date.
Otherwise print the weekday of the first date (strftime("%A")), the number of days between the two dates, and the later of the two dates.
Input Format
- Line 1: the first date
- Line 2: the second date
Output Format
- Line 1:
Weekday: <day name> - Line 2:
Days between: <n>(always positive or 0) - Line 3:
Later date: <YYYY-MM-DD> - If a date is invalid, print only
Invalid date
Constraints
- Years are between 1 and 9999
Sample Test Cases
Sample 1
Input
2026-01-26 2026-08-15
Output
Weekday: Monday Days between: 201 Later date: 2026-08-15
Sample 2
Input
2024-02-30 2024-03-01
Output
Invalid date
Submitting checks 2 sample cases and 3 hidden test cases.