Home >Backend Development >Python Tutorial >How to determine leap year in python
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
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!