21.8k views
21 votes
A year with 366 days is called a leap year. Leap years are necessary to keep the calendar in sync with the sun, because the earth revolves around the sun once very 365.25 days. As a result, years that are divisible by 4, like 1996, are leap years. However, years that are divisible by 100, like 1900, are not leap years. But years that are divisible by 400, like 2000, are leap years. Write a program named leap_year.py that asks the user for a year and computes whether that year is a leap year.

User MythThrazz
by
7.1k points

1 Answer

9 votes

Answer:

Follows are the code to this question:

y = int(input("Enter a year: "))#input year value

if((y%4==0) and (y%100==0) or y%400==0):#defining if block for check leap year condition

print("Given year {0}, is a leap year".format(y))#print value

else:#else block

print("Given year {0}, is not a leap year".format(y))#print value

Output:

Enter a year: 1989

Given year 1989, is not a leap year

Explanation:

In the python code, the y variable uses the input method for input the value from the user-end. In the next step, if a conditional block is used, that's checks the leap-year condition. if the condition is true it will print leap year value with the message, otherwise, it will go to else block that prints not a leap year message.

User Stefan Judis
by
7.5k points