首页 > 文章列表 > 如何用python写月份

如何用python写月份

Python
276 2022-08-07

用python写月份的方法:

调用input方法输入月份,用if elif循环结构筛选符合条件的信息,然后再用print打印运行结果

month = int(input('Month:'))
  if month in [3,4,5]:
      print('春季')
  elif month in [6,7,8]:
      print('夏季')
  elif month in [9,10,11]:
      print('秋季')
  elif month in [12,1,2]:
      print('冬季')
  else:
      print('请输入正确值:')

示例以及运行结果: