Program 41: Take a year as input and print whether it is a leap year or not [Python]


Question: Write a Python Program that takes a year as input and prints whether it is a leap year or not.


Solution:

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

if (year % 4) == 0:
  if (year % 100) == 0:
    if (year % 400) == 0:
      print(f"{year} is a leap year") 
    else:
      print(f"{year} is not a leap year")
  else:
    print(f"{year} is a leap year")
else:
  print(f"{year} is not a leap year")
Output:

Enter a year: 2024
2024 is a leap year


Notebook Example:

Notebook Demo - Leap Year Python

These Python programs are created by experienced programmers to aid students in learning Python. We are here to make your learning experience as interactive and informative as possible. If you have questions or need more clarification, feel free to ask. Happy coding!

Please support independent contributors like Code2care by donating a coffee.

Buy me a coffee!

Buy Code2care a Coffee!

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!