Python program to check leap year

Configurare noua (How To)

Situatie

A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400.

Solutie

Pasi de urmat

# Python program to check if year is a leap year or not

year = 2000

# To get year (integer input) from the user
# year = int(input(“Enter a year: “))

# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
print(“{0} is a leap year”.format(year))

# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
print(“{0} is a leap year”.format(year))

# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
print(“{0} is not a leap year”.format(year))

Output:

2000 is a leap year

Tip solutie

Permanent

Voteaza

(8 din 16 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?