CBSE Class 11 Computer Science Question 128 of 161

Flow of Control — Question 5

Back to all questions
5
Question

Question 5

A year is a leap year if it is divisible by 4, except that years divisible by 100 are not leap years unless they are also divisible by 400. Write a program that asks the user for a year and prints out whether it is a leap year or not.

Solution
year = int(input("Enter year: "))

if year % 400 == 0 :
    print(year, "is a Leap Year")
elif year % 100 == 0 :
    print(year, "is not a Leap Year")
elif year % 4 == 0 :
    print(year, "is a Leap Year")
else :
    print(year, "is not a Leap Year")
Output
Enter year: 1800
1800 is not a Leap Year
Answer