Kodewick
开始学 →
小挑战←→0 / 100

是不是闰年

#012小挑战条件数字约 6 分钟

日历要知道二月有几天。闰年的规则:能被 4 整除,但不能被 100 整除;或者能被 400 整除。写 is_leap(year),是闰年返回 True。

示例
is_leap(2024)→True
is_leap(2023)→False
is_leap(1900)→False
main.py
def is_leap(year):
    by4 = year % 4 == 0
    by100 = year % 100 == 0
    by400 = year % 400 == 0
    # 在这里写:用 and / or / not 把三个条件组合起来
    pass
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。