其他分享
首页 > 其他分享> > The month's days(leap year defination)

The month's days(leap year defination)

作者:互联网

leap year:

1.  能被400整除的是闰年

2. 不能被100整除但能被4整除的是闰年

 

if a year is divisible by 4 and not divisible by 100 or divisible by 400,it is a leap year

 

Given a year and month, return the days of that month.  
class Solution:
    """
    @param year: a number year
    @param month: a number month
    @return: return the number of days of the month.
    """
    def get_the_month_days(self, year, month):
        # write your code here
        # 给定年份和月数,算出这个月有多少天
        # 除了闰年的2月份,每个月的天数都是固定的
        day = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        if month == 2:
            # 能被400整除的是闰年
            if year % 400 == 0:
                return 29
            # 不能被100整除但能被4整除的是闰年
            if year % 4 == 0 and year % 100 != 0:
                return 29
        
        return day[month]
            
            

 

标签:return,闰年,defination,31,month,leap,year,整除
来源: https://www.cnblogs.com/zijidan/p/16255808.html