Ad Code

Write a program that prompts the user to input a year and determine whether the year is a leap year or not. Leap Years are any year that can be evenly divided by 4. A year that is evenly divisible by 100 is a leap year only if it is also evenly divisible by 400. Example : 1992 Leap Year 2000 Leap Year 1900 NOT a Leap Year 1995 NOT a Leap Year

Write a program that prompts the user to input a year and determine whether the year is a leap year or not.

Leap Years are any year that can be evenly divided by 4. A year that is evenly divisible by 100 is a leap year only if it is also evenly divisible by 400. Example :

1992

Leap Year

2000

Leap Year

1900

NOT a Leap Year

1995

NOT a Leap Year

Code:

def is_leap_year(year):
    if year % 4 == 0:  # Check if the year is divisible by 4
        if year % 100 == 0:  # Check if the year is divisible by 100
            if year % 400 == 0:  # Check if the year is divisible by 400
                return True  # Leap year
            else:
                return False  # Not a leap year
        else:
            return True  # Leap year
    else:
        return False  # Not a leap year

# Prompt the user to input a year
year = int(input("Enter a year: "))

# Check if the entered year is a leap year or not
if is_leap_year(year):
    print(year, "is a Leap Year")
else:
    print(year, "is NOT a Leap Year")
Reactions

Post a Comment

0 Comments