I couldn't find a thread that was related. I am working on a seasons lab. I need to be able to take a month and day and print the season. It needs to print invalid for days that are not calendars days and strange inputs. I decided to use lists, but they keep printing out blank outputs. I am not sure where my code is just ending.
input_month = str(input()).lower() # make user input a lower case string input_month = input_month.replace(' ', '') # remove spaces in user input input_day = int(input()) # make user input a number # list of seasons spring = ['march', 'april', 'may', 'june'] summer = ['june', 'july', 'august', 'september'] autumn = ['september', 'october', 'november', 'december'] winter = ['december', 'january', 'february', 'march'] season = ['Spring', 'Summer', 'Autumn', 'Winter'] if input_month in spring: # "march" or 'april' or 'may' or 'june': if (input_month == spring[0]) and (31 >= input_day > 19): season = season[0] print(season) elif (input_month == spring[0]) and (1 <= input_day < 19): season = season[3] print(season) elif (input_month == spring[3]) and (1 <= input_day < 21): season = season[0] print(season) elif (input_month == spring[3]) and (31 <= input_day > 21): season = season[1] print(season) elif (input_month == spring[1] or input_month == spring[2]) and (1 <= input_day <= 31): season = season[0] print(season) else: print('Invalid')
The input month of "april" is not equal to anything in the spring list/array. the formatting is wrong somewhere.
2.1m questions
2.1m answers
60 comments
57.0k users