Next Day
Programming Basics · Python
TASK
Problem
Given valid `day month` in a non-leap year, print the next date as `day month`.
EXAMPLE
Example
28 2
1 3
LIMITS
Constraints
date is valid; non-leap year
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. The `+` operator adds numbers. 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 `day` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['At month end, reset day to 1 and increment month; after 12 comes 1.']
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:
day += 1
else:
day = 1
if month == 12:
month = 1
else:
month += 1
print(day, month)