Вот синтаксически правильный код (с обратными косыми чертами):
input_month = input()
input_day = int(input())
if input_month == 'March' and 20 <= input_day <= 31 or input_month \
== 'June' and 1 <= input_day <= 20:
print('Spring')
elif input_month == 'June' and 21 <= input_day <= 30 or input_month \
== 'September' and 1 <= input_day <= 30:
print('Summer')
elif input_month == 'September' and 22 <= input_day <= 30 \
or input_month == 'December' and 1 <= input_day <= 20:
print('Autumn')
elif input_month == 'December' and 21 <= input_day <= 31 or input_month \
== 'January' and 1 <= input_day <= 31 or input_month == 'February' \
and 1 <= input_day <= 28 or input_month == 'March' and 1 \
<= input_day <= 19:
print('Winter')
Однако есть способы сделать решение более читабельным, pythoni c и компактным. Например, вот так:
MONTHS = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December"]
BOUNDARIES = [((3, 20), (6, 20), "Spring"),
((6, 21), (9, 21), "Summer"), # FIXED THE UPPER BOUNDARY
((9, 22), (12, 20), "Autumn"),
((12, 21), (12, 31), "Winter"),
((1, 1), (3, 19), "Winter")]
input_month = input()
input_day = int(input())
input_date = (MONTHS.index(input_month) + 1, input_day)
for lower, upper, season in BOUNDARIES:
if lower <= input_date <= upper:
print(season)
break
или (менее эффективный способ) вот так:
SEASONS = {"Spring": [
("March", (20, 32)),
("June", (1, 21)),
],
"Summer": [
("June", (21, 31)),
("September", (1, 31)),
],
"Autumn": [
("September", (22, 31)),
("December", (1, 21)),
],
"Winter": [
("December", (21, 32)),
("January", (1, 32)),
("February", (1, 29)),
("March", (1, 20)),
]
}
input_month = input()
input_day = int(input())
for season in SEASONS:
for month, day_ranges in SEASONS[season]:
if input_month == month and input_day in range(*day_ranges):
print(season)
else:
continue
break