CampusX SDE Sheet | Write a program that will tell whether the given year is a leap year or not.

 Write a program that will tell whether the given year is a leap year or not

little boy seeing the calender to check which year is leap year and which is not a leap year



'''
Write a program that will tell whether the given year is a leap year or not.
'''

def leap_year(year):
    if (year%4 == 0) and ((year%100 != 0) or (year%400 == 0)):
        return True
    else:
        return False

try:
    user_input = int(input("Enter a year: "))
    if leap_year(user_input):
        print(f"{user_input} is a leap year.")
    else:
        print(f"{user_input} is not a leap year.")
except ValueError:
    print("Please enter a valid year (integer).")

Post a Comment

Previous Post Next Post