Home >Backend Development >Python Tutorial >How to determine leap year in python

How to determine leap year in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-22 14:17:1319534browse

Ordinary leap year: divisible by 4, not divisible by 100
Century leap year: divisible by 400
Number of days in leap year: 366 days
January to December are 31 days, 29 days, 31 days respectively , 30 days, 31 days, 30 days, 31 days, 31 days, 30 days, 31 days, 30 days, 31 days

# Ordinary leap year
year = year%4
# Century leap year
year = year@0

How to determine leap year in python

Related recommendations: "Python Video Tutorial"

years = int(input("请输入查询的年份: "))
if (years % 4 == 0 and years % 100 != 0) or (years % 400 == 0):
    print(years, "是闰年")
else:
    print(years, "不是闰年")

Execute the above code The output is:

请输入查询的年份: 2019
2019 不是闰年
请输入查询的年份: 2020
2020 是闰年

The above is the detailed content of How to determine leap year in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn