编写程序,输入月份,输出该月份对应的季节名称

12.1.2月是冬季,3.4.5是春季,6.7.8是夏季,9.10.11是秋季

month=int(input("输入月份:"))
if month==12 or month==1 or month==2:
print("冬季")
elif 3<=month<=5:
print("春季")
elif 6<=month<=8:
print("夏季")
elif 9<=month<=11:
print("秋季")
else:
print("输入错误")


month = input('请输入月份:')
season = {
  "1": "冬季",
  "2": "冬季",
  "3": "春季",
  "4": "春季",
  "5": "春季",
  "6": "夏季",
  "7": "夏季",
  "8": "夏季",
  "9": "秋季",
  "10": "秋季",
  "11": "秋季",
  "12": "冬季",
}
season_text = season.get(month)
if season_text == None:
  season_text = "无效月份"

print(f'{month}月份对应的季节名称:{season_text}')

img

seasons = {'冬季':[12,1,2],'春季':[3,4,5],'夏季':[6,7,8],'秋季':[9,10,11]}

month = int(input('请输入月份:'))
for i in seasons:
    if month in seasons[i]:
        print(i)
        break
m = int(input("输入月份:"))
print('冬春夏秋'[m//3%4]+'季')