Question: a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int
a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day.
I have the months working correctly, just can't figure out how to get an output of 'Invalid' if the day is not 1 - 31. for instance a -1 or 37 entered for the day should produce an output of 'Invalid'. If I put in April for the month and 37 for the date, I get an output of Spring, while it should be 'Invalid". I have tried multiple approaches.
month = input()
day = int(input())
if month in ('January', 'February', 'March'):
season = 'Winter'
elif month in ('April', 'May', 'June'):
season = 'Spring'
elif month in ('July', 'August', 'September'):
season = 'Summer'
elif month in ('October', 'November', 'December'):
season = 'Autumn'
elif month != ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'):
season = 'Invalid'
if (month == 'March') and (day > 19):
season = 'Spring'
elif (month == 'June') and (day > 20):
season = 'Summer'
elif (month == 'September') and (day > 21):
season = 'Autumn'
elif (month == 'December') and (day > 20):
season = 'Winter'
if (0 < day < 32):
season = 'Invalid'
print(season)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
