【每日一题20220622】判断闰年

:mage:‍ 给定一个数字年份,请判断它是否是闰年。具体规则如下:

  1. 非整百年:能被4整除的为闰年;
  2. 整百年:能被400整除的是闰年。

【示例】
输入:2000
输出:True
解释:2000年可以被400整除。

题目难度:简单
题目来源:codewars-Leap Years

def solution(year: int)-> bool:
    # your code here

assert solution(2000) is True
assert solution(1984) is True
assert solution(1900) is False
def solution(year: int)-> bool:
    # your code here
   return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0

assert solution(2000) is True
assert solution(1984) is True
assert solution(1900) is False
def solution(year: int)-> bool:
    return ((year % 100 != 0 and year % 4 == 0) or year % 400 == 0)


if __name__ == '__main__':
    assert solution(2000) is True
    assert solution(1984) is True
    assert solution(1900) is False
def solution(year: int)-> bool:
    if year % 100 ==0:
        return year % 400 == 0
    else:
        return year % 4 == 0

assert solution(2000) is True
assert solution(1984) is True
assert solution(1900) is False

falg = True
def leap(year):

if year % 4 ==0 and year % 100 != 0 or year % 400 ==0:
    falg = True
else:
    falg = False
return falg

print(leap(2003))

def solution(year: int)-> bool:
    return True if year % 100==0 and year%400==0 else year % 100!=0 and year%4==0
def solution(year: int)-> bool:
    return year % 100!=0 and year % 4==0 or year % 400==0
def solution(year: int)-> bool:
    if year%400 == 0:
        return True
    elif year%100 == 0:
        return False
    elif year%4 == 0:
        return True
    else:
        return False

assert solution(2000) is True
assert solution(1984) is True
assert solution(1900) is False
def solution(year: int) -> bool:
    # your code here
    # if year % 100 == 0 and year % 400 == 0:
    #     return True
    # elif year % 100 != 0 and year % 4 == 0:
    #     return True
    # else:
    #     return False
    return year % 100 != 0 and year % 4 == 0 or year % 400 == 0


assert solution(2000) is True
assert solution(1984) is True
assert solution(1900) is False
def isLeapYear(year):
    if year % 100 !=0 and year % 4 ==0 or year % 400 ==0:
        return True
    return False
def solution(year: int)-> bool:
    if str(year)[-2:] != '00':
        return True if year%4==0 else False
    else:
        return True if year%400==0 else False

assert solution(2000) is True
assert solution(1984) is True
assert solution(1900) is False