Loading...
Loading...
A date is valid when the month is 1 to 12 and the day exists in that month. April, June, September and November have 30 days. February has 29 days in a leap year and 28 otherwise. The other months have 31 days. A leap year is divisible by 4, except century years, which must be divisible by 400.
Given a day, a month and a year, print Valid or Invalid.
Valid or Invalid.Example 1
Input
29 2 2024
Output
Valid
Example 2
Input
31 4 2023
Output
Invalid
Try the problem first. Open one hint at a time.
First find the number of days in the month. Use match-case on the month with an or pattern for the 30-day months.
For an invalid month set the number of days to 0, so that every day fails. A valid day is at least 1 and at most the number of days.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor