Home  >  Article  >  Backend Development  >  How to determine whether a certain year is a leap year in python

How to determine whether a certain year is a leap year in python

王林
王林Original
2020-05-06 13:26:0712139browse

How to determine whether a certain year is a leap year in python

Objective:
Find whether the given year is a leap year.

Analysis:

It is a leap year if any one of the following two points is met:

A: It can be evenly divisible by 4, but not evenly divisible by 100;

B : Divisible by 400.

Code example:

year = int(input('请输入一个年份:'))

if year % 4 == 0 and year % 100 != 0:
    print('闰年')
elif year % 400 == 0:
    print('闰年')
else:
    print('平年')

Recommended tutorial: python tutorial

The above is the detailed content of How to determine whether a certain year is a 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