Home > Backend Development > Python Tutorial > 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

王林
Release: 2020-05-06 13:26:07
Original
12213 people have browsed it

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('平年')
Copy after login

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!

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