Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
900 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

1 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...