PROBLEM 82
Medium

Date Validation

Programming Basics · Python

</>
STATUS Not solved

TASK

Problem

#82

Given `day` and `month` in a non-leap year, print `VALID` if the date exists, otherwise `INVALID`.

EXAMPLE

Example

Input
31 4
Output
INVALID

LIMITS

Constraints

1 ≤ month ≤ 12; 1 ≤ day ≤ 31
📖
LEARN Theory for this problem
+

`input()` reads data entered by the user. The result of `input()` is initially a string. `split()` separates one input line into individual values using spaces. `map()` applies the specified conversion to each input value. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `or` requires at least one condition to be true. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. `print()` displays the program result. Print only what the problem statement requires.

**Connection to this task.** An `if` statement chooses a program branch from a Boolean condition. Comparisons produce `True` or `False`, and `elif` lets you test several mutually exclusive cases in order. The expression `'VALID'` shows how this idea is applied to the task data.

💡
NEED HELP? Hints
+

['Determine days in the month and compare with `day`.']

ANSWER Solution
+
day, month = map(int, input().split())
if month == 2:
    limit = 28
elif month == 4 or month == 6 or month == 9 or (month == 11):
    limit = 30
else:
    limit = 31
if day <= limit:
    print('VALID')
else:
    print('INVALID')