How to determine leap year in python

爱喝马黛茶的安东尼
Release: 2019-06-22 14:17:13
Original
19495 people have browsed it

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, "不是闰年")
Copy after login

Execute the above code The output is:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template