描述‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    一个8位表示的年月日,如20200220,前4位表示年份,5-6位表示月份,7-8位表示日期。编写程序对日期数据进行处理和分析。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    输入格式‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    第一行输入一个8位长度的日期形式(题目确保输入的字符串只包含0-9的数字,且长度为8位)‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    第二行输入一个分割符号sign‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    输出格式‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬

    1. 根据输入数据中表示年份的数字判断是否为闰年。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    2. 输出当前月份共有多少天?‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    3. 输出用sign符号分隔的日期输出,例如输入”/“,输出2020/09/09。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    4. 只考虑月份和日期的合法性,判断输入的数字是否为一个合法的日期。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    5. 输出当前月份的单词和缩写形式‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬

    输入输出示例 示例仅为格式展示,与测试数据无关‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    示例 1‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    输入:
    20200229
    /
    输出:
    2020年是闰年
    2020年2月有29天
    2020/02/29
    20200229是合法日期
    2月英文是February,缩写为Feb.
    示例 2‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬
    输入:
    18000231
    @
    输出:
    1800年不是闰年
    1800年2月有28天
    1800@02@31
    18000231是非法日期
    2月英文是February,缩写为Feb.

    1. # ------------ ------- -------- ----------- -----------
    2. # @File : 6.4.3 日期分析处理实验模板.py
    3. # @Contact : vasp@qq.com
    4. # @Copyright : 2018-2025, Wuhan University of Technology
    5. # @Modify Time: 2021/4/27 15:27
    6. # @Author : 赵广辉
    7. # @Version : 1.0
    8. # @License : 仅限用于Python程序设计基础实践教程(赵广辉,高等教育出版社)配套实验
    9. # ------------ ------- -------- ----------- -----------
    10. def leap(current_date):
    11. """接收一个用8个字符表示日期的字符串为参数,判断这个日期中的年份是否为闰年
    12. 返回值为布尔型。
    13. @参数 current_date:表示日期,字符串类型
    14. 闰年的判定方法是:能被400整除或能被4整除且同时不能被100整除的是闰年。
    15. """
    16. year = int(current_date[:4])
    17. if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
    18. return True
    19. else:
    20. return False
    21. def legal_judge(current_date):
    22. """接收一个用8个字符表示日期的字符串为参数,判定日期的合法性,返回值为布尔型。
    23. 1,3,5,7,8,10,12月各31天,4,6,9,11各30天,闰年2月29天,平年2月28天。
    24. @参数 current_date:表示日期,字符串类型
    25. """
    26. month = int(current_date[4:6])
    27. date = int(current_date[6:])
    28. if month > 12:
    29. return False
    30. elif date > days_of_month(current_date):
    31. return False
    32. else:
    33. return True
    34. def days_of_month(current_date):
    35. """接收一个用8个字符表示日期的字符串为参数,若月份合法,返回这个月份有多少天的整数,
    36. 否则返回字符串"'**月份数字不合法'",**表示月份。
    37. 参数 current_date:表示日期,字符串类型
    38. """
    39. if int(current_date[4:6]) <=12:
    40. months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    41. current_month_order = int(current_date[4:6]) - 1
    42. current_month_days = months[current_month_order]
    43. if leap(current_date) and current_date[4:6] == '02':
    44. current_month_days = current_month_days + 1
    45. return current_month_days
    46. else:
    47. return f'{current_date[4:6]}月份数字不合法'
    48. def name_of_month(current_date):
    49. """接收一个用8个字符表示日期的字符串为参数,返回这个月份对应的英文单词及其缩写形式。
    50. 9月缩写为'Sept.',此时返回值为:'September','Sept.'
    51. """
    52. months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
    53. 'November', 'December']
    54. month_abbr = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.']
    55. month_order = int(current_date[4:6])-1
    56. return months[month_order],month_abbr[month_order]
    57. def separate_date(current_date, symbol):
    58. """接收一个用8个字符表示日期的字符串和一个符号为参数,返回用该符号分隔的日期,字符串类型。
    59. @参数 current_date:表示日期,字符串类型
    60. @参数 symbol:分隔符号,字符串类型
    61. 例如传入'20201031'和"/",返回字符串'2020/09/09'
    62. """
    63. year = current_date[:4]
    64. month = current_date[4:6]
    65. date = current_date[6:]
    66. return symbol.join([year, month, date])
    67. def test(current_date):
    68. if leap(current_date):
    69. print(f'{current_date[:4]}年是闰年')
    70. else:
    71. print(f'{current_date[:4]}年不是闰年')
    72. days = days_of_month(current_date)
    73. print(f'{current_date[:4]}年{int(current_date[4:6])}月有{days}天')
    74. print(separate_date(current_date, sign))
    75. if legal_judge(current_date):
    76. print(f'{current_date}是合法日期')
    77. else:
    78. print(f'{current_date}是非法日期')
    79. month_name, month_abbr = name_of_month(current_date)
    80. print(f'{int(current_date[4:6])}月英文是{month_name},缩写为{month_abbr}')
    81. if __name__ == '__main__':
    82. CurrentDate = input()
    83. sign = input()
    84. test(CurrentDate)