Posts

Showing posts with the label If-else

Python Program to Check Leap Year or Not

Image
  In this post, we will write a python program to check an inputted program, a leap year or not. General Idea : A leap is a year that has 366 days. It will come once in a four year. To check whether a year is a leap year or not can be easily verified with the year itself. If the year is divisible by 400 as the year 2000, it's a leap year. Or otherwise, if the year is not divisible by 100 but divisible by 4 as the year 2004, it's a leap year. Except these everything is not a leap year. Pre-Requisites : Python Basics Conditional Statements Program : n=int(input("Enter a Year ")) if ((n%400==0)or((n%100!=0)and(n%4==0))):     print(n," is a leap year") else :     print(n," is not a leap year") Explanation : 1. First we need to get the year for which we need to check whether it's a leap year or not. Here we are inputting the year using the input function and storing it to a variable 'n'. 2. Here we are using the if statement to check whether...