Write a program to check if the year entered by the user is a leap year or not.
Question
Write a program to check if the year entered by the user is a leap year or not.
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Here's a Python program to check if the year entered by the user is a leap year or not:
# Program to check if a year is a leap year or not
# Input: year to be checked
year = int(input("Enter a year: "))
# Logic to check if it's a leap year
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(year, "is a leap year.")
else:
print(year, "is not a leap year.")
Explanation:
Leap Year Rule: A year is a leap year if:
It is exactly divisible by 4 and not exactly divisible by 100 OR
It is exactly divisible by 400.
Input: The year to be checked (entered by the user).
Output: Displays whether the year is a leap year or not.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month