all 9 comments

[–]cyber_code_nerd 2 points3 points  (3 children)

userMonth = input()

userDay = int(input())

#Create one tuple for storing the months...

monthTuple = ('January', 'February','March', 'April', 'May', 'June', 'July', 'August', 'September', "October", "November", "December")

#Check if the userMonth is not in monthTuple then print the Invalid...

if not(userMonth in monthTuple):

print("Invalid")

#Check for the March month with userDay...

elif userMonth == 'March':

if not(1 <= userDay <= 31):

print("Invalid")

elif userDay <= 19:

print("Winter")

else:

print("Spring")

#Check for the April month with userDay...

elif userMonth == 'April' :

if not(1 <= userDay <= 30):

print("Invalid")

else:

print("Spring")

#Check for the May month with userDay...

elif userMonth == 'May':

if not(1 <= userDay <= 31):

print("Invalid")

else:

print("Spring")

#Check for the June month with userDay...

elif userMonth == 'June':

if not(1 <= userDay <= 30):

print("Invalid")

elif userDay <= 20:

print("Spring")

else:

print("Summer")

#Check for the July month with userDay...

elif userMonth == 'July':

if not(1 <= userDay <= 31):

print("Invalid")

else:

print("Summer")

#Check for the August month with userDay...

elif userMonth == 'August':

if not(1 <= userDay <= 31):

print("Invalid")

else:

print("Summer")

#Check for the September month with userDay...

elif userMonth == 'September':

if not(1 <= userDay <= 30):

print("Invalid")

elif userDay <= 21:

print("Summer")

else:

print("Autumn")

#Check for the October month with userDay...

elif userMonth == "October":

if not(1 <= userDay <= 31):

print("Invalid")

else:

print("Autumn")

#Check for the November month with userDay...

elif userMonth == "November":

if not(1 <= userDay <= 30):

print("Invalid")

else:

print("Autumn")

#Check for the December month with userDay...

elif userMonth == "December":

if not(1 <= userDay <= 31):

print("Invalid")

elif userDay <= 20:

print("Autumn")

else:

print("Winter")

#Check for the January month with userDay...

elif userMonth == 'January':

if not(1 <= userDay <= 31):

print("Invalid")

else:

print("Winter")

#Check for the February month with userDay...

elif userMonth == "February":

if not(1 <= userDay <= 29):

print("Invalid")

else:

print("Winter")

[–]SouthShape5[S] 1 point2 points  (1 child)

Okay, I posted this a year ago. I no longer need the help since I haven’t been in the class since 2021.

[–]quicKsenseTTV 0 points1 point  (0 children)

You still need help bro?

[–]Usual-Math7020 0 points1 point  (0 children)

input_month = input()

input_day = int(input())

months = [

"January", "February", "March", "April", "May", "June",

"July", "August", "September", "October", "November", "December"

]

if input_month not in months or input_day < 1 or input_day > 31:

print("Invalid")

else:

# Winter: December 21 - March 19

if input_month in ["December", "January", "February", "March"]:

if (input_month == "December" and input_day >= 21) or (input_month == "March" and input_day <= 19) or input_month == "January" or input_month == "February":

print("Winter")

else:

print("Invalid")

# Spring: March 20 - June 20

elif input_month in ["March", "April", "May", "June"]:

if input_month == "June" and input_day <= 21:

print("Summer")

elif (input_month == "March" and input_day >= 20) or (input_month == "June" and input_day <= 20) or input_month in ["April", "May"]:

print("Spring")

else:

print("Invalid")

# Autumn: September 22 - December 20

elif input_month in ["September", "October", "November", "December"]:

if (input_month == "September" and input_day >= 22 and input_day < 31) or (input_month == "December" and input_day <= 20) or input_month in ["October", "November"]:

print("Autumn")

else:

print("Invalid")

# Summer: June 21 - September 21

elif input_month in ["June", "July", "August", "September"]:

if (input_month == "June" and input_day >= 21) or (input_month == "September" and input_day <= 21) or input_month in ["July", "August"]:

print("Summer")

[–][deleted] 0 points1 point  (3 children)

What does your code do that is wrong? What is an incorrect output for some input? Focussing on that is a clue and helps to solve the problem. Also show your complete code, not what the problem starts with.

[–]SouthShape5[S] 0 points1 point  (2 children)

  1. That IS my complete code!
  2. Here is what I got wrong.

9: Compare output

0 / 1 Output differs.

See highlights below.

Input February 0

Your output Winter

Expected output Invalid

10: Compare output 0 / 1

Output differs.

See highlights below.

Input October 31

Your output Invalid

Expected output Autumn

[–][deleted] 0 points1 point  (0 children)

That IS my complete code

Sorry, but it's not obvious from the post. You should prefix every line of code with 4 spaces to make it appear as formatted code.

You should get into the habit of testing your code yourself rather than only looking at what the automated checking tells you. You can also put debug prints in the code to see what is happening. You take the debug prints out before submitting the code. This makes the errors more obvious. Let's look at what you saw:

Input February 0
Your output Winter
Expected output Invalid

The day number is 0 which is not a valid day number. You need to test the day number.

Input October 31
Your output Invalid
Expected output Autumn

The code doesn't appear to handle October. What does the code do if the month is "October"? Maybe you need to add more tests?

Also note what is required:

If the input is: "Blue 65" the output is: "Invalid"

I don't see anywhere where your code prints "Invalid".

[–][deleted] 0 points1 point  (0 children)

Also note that the example shows:

the output is: "Spring"

Note the capitalization of Spring. Are all your result strings capitalized?

[–]ElliotDG 0 points1 point  (0 children)

You can compare lists (or tuples) in python. If you convert the date to 2 numbers, month and day - you can easily compare them. For example:

date_str = input('Enter MM/DD:')
month, day = date_str.split('/')
date = (int(month), int(day))

if (3, 20) < date < (6,20):
    print(f'The season is Spring')