tisuki_t 2022-05-07 13:44 采纳率: 87.5%
浏览 2078

python本月天数(函数)编程问题

img


想问问这个是哪儿错了,如图所示,求第几月的第几天又怎么做呢?python函数

  • 写回答

7条回答 默认 最新

  • 树下等苹果 2022-05-07 14:02
    关注

    代码改正如下:

    def is_leap(year):
        # 判断year是否为闰年,闰年返回True,非闰年返回False
        if (year % 100 != 0 and year % 4 == 0) or year % 400 == 0:
            return True
        else:
            return False
    
    
    def days_of_month(year,month):
        # 根据输入的年月日,返回该月的天数
        tian = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        if is_leap(year):
            tian[1] = 29
        print(tian[month-1])
    
    str = input("输入:")
    year = int(str[0:4])
    month = int(str[4:6])
    days_of_month(year,month)
    
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 5月7日