Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

link index printing blank python

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')
question from:https://stackoverflow.com/questions/65860166/link-index-printing-blank-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

The input month of "april" is not equal to anything in the spring list/array. the formatting is wrong somewhere.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...