13.9k views
2 votes
A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are:

1) If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
2) If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
3) If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
4) The year is a leap year (it has 366 days).
5) The year is not a leap year (it has 365 days).
Some example leap years are 1600, 1712, and 2016.
Write a program that takes in a year and determines whether that year is a leap year.

User AfroThundr
by
3.8k points

1 Answer

3 votes

Answer:

The program in Python is as follows:

year = int(input("Year: "))

print(year,end=" ")

if (year % 4) == 0:

if (year % 100) == 0:

if (year % 400) == 0:

print("is a leap year")

else:

print("is not a leap year")

else:

print("is a leap year")

else:

print("is not a leap year")

Step-by-step explanation:

This gets input for year

year = int(input("Year: "))

This prints the year, input by the user

print(year,end=" ")

Check if year is divisible by 4 --- step 1

if (year % 4) == 0:

If step 1 is true, check if year is divisible by 100 -- step 2

if (year % 100) == 0:

If step 2 is true, check if year is divisible by 400 -- step 3

if (year % 400) == 0:

If yes, print leap year --- step 4

print("is a leap year")

else:

If otherwise, print not leap year --- step 5

print("is not a leap year")

If step 3 is not true, print leap year

else:

print("is a leap year")

If step 1 is not true, print not leap year

else:

print("is not a leap year")

User NemoStein
by
3.9k points