Python program- Writing a program to input a year and check whether the year is leap year or not. This python project is useful for beginners and CBSE KV Computer Science practical file. The step wise details with input source file and out put.
What is Leap Year ?
Leap years are years where an extra day is added to the end of February. February 29, is commonly referred to as leap day. Leap years have 366 days instead of the usual 365 days and occur almost every four years.
Rules to calculate Leap Year:
- The year must be divisible by 4;
- If the year can also be evenly divided by 100, it is not a leap year;
- unless…The year is also evenly divisible by 400. Then it is a leap year.
Make a Python Program for Leap Year
Now we are going to make a program in Python to check whether the year is leap year or not using the above leap year calculation rule.
y=int(input(“Enter the year: “)) #the year is entered
if y%400==0: # checked if it is divisible by 400 %checks for remainder
print(“The year is a Century Leap Year”) # prints if remainder is zero
elif y%100!=0 and y%4==0: # check not divisible by 100 but divisible by 4
print(“Year is a Leap year”) # if above condition is truth then year is a leap year is printed
else: # else it is printed year is not a leap year
print(“Year is not a leap year”)
y=int(input(“Enter the year: “)) #the y here is a variable and the input is taken in integer
Test the Leap Year Program
Run (F5) the program and enter any year. In sample case we entered 2020. The program will run as following :-
- Check if if is divided by 400. condition is not true.
- Now it will check (elif) not divide by 100. condition matched. Therefore, it will print statement “Year is a leap year”
Success. You are able to a make a basic Python Program. Keep on going.
Input a welcome message and display it in Python
Display the larger / smaller number in Python.
Greatest of Three Numbers in Python using Nested if
Patterns using nested loop in Python
Program to Print Pattern in Python
Program to input the value of x and n and sum of series in Python
Python Program for Armstrong, Prefect Number, Palindrome
Program of Prime number by recursion in python
Prime Number Program in Python
Write a Program to Print Fibonacci Series in Python
Python program to count number of vowels in a string
Whether a String is Palindrome or not in Python
Linear search in python using list
Program to read a text file in python
Python program to read a file line by line
Program to Count Vowels and Consonants in Python
Python Leap Year Program for Beginners
Python Program to Print Series and Addition
Binary Search Program in Python
Program to find sum of digits in python
Sum of numbers divisible by 3 and 5 in python