ITPub博客

首页 > IT职业 > IT职场 > 如何用python写月份

如何用python写月份

IT职场 作者:xduu 时间:2021-09-11 10:15:18 0 删除 编辑

用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('请输入正确值:')

示例以及运行结果:

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2195/viewspace-2833387/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-16

  • 博文量
    84
  • 访问量
    998