In: Computer Science
Exercise 8: Season from Month and Day The year is divided into four seasons: spring, summer, fall and winter. While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise:
Season - First day
Spring - March 20
Summer - June 21
Fall - September 22
Winter - December 21
Create a program that reads a month and day from the user. The user will enter the name of the month as a string, followed by the day within the month as an integer. Then your program should display the season associated with the date that was entered.
used python
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
#Getting month as input from the user
m = input("Enter Month: ")
#Getting day as input from the user
d = int(input("Enter day: "))
#if month in January, February, March
if m in ('January','February','March'):
#season = Winter
s = 'Winter'
#if month in April, May, June
elif m in ('April','May','June'):
#season = Spring
s = 'Spring'
#if month in July, August, September
elif m in ('July','August','September'):
#season = Summer
s = 'Summer'
#if month in October, November, December
elif m in ('October','November','December'):
#season = Fall
s = 'Fall'
#if month is March and day >= 20
if(m == 'March') and (d >= 20):
#season = Spring
s = 'Spring'
#if month is June and day >= 21
elif(m == 'June') and (d >= 21):
#season = Summer
s = 'Summer'
#if month is September and day >= 20
elif(m == 'September') and (d >= 22):
#season = Fall
s = 'Fall'
#if month = December and day >= 21
elif(m == 'December') and (d >= 21):
#season = Winter
s = 'Winter'
#printing season associated with the date
print(s,"-",m,d)
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!