Objective
Create a Python program that parses dates written as day/month/year and converts them to the standard ISO format, detecting the invalid ones. The strptime method does the opposite conversion of strftime and raises ValueError when the text does not match.
Instructions
- Read an integer
nand thenntexts, one per line (no spaces). - Try to convert each text with
datetime.strptime(text, "%d/%m/%Y"). If it works, show the date withisoformat()(YYYY-MM-DD). - If it raises
ValueError(wrong format, or an impossible date such as 31 April), showInvalid date: textwith the original text.
4
15/03/2026
31/04/2026
2026-03-15
29/02/2024
2026-03-15
Invalid date: 31/04/2026
Invalid date: 2026-03-15
2024-02-29
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise