Hello World !
Today we are going to learn leap year program in python. We are going to implement it in python
What will be covered :
What is a leap year?
Arithmetic operation.
Conditional statements
What is a leap year?
A leap year is a calendar year that contains an additional day in the month of february added to keep the calendar year synchronised with the astronomical year.
Here are the rules of leap years:
A year may be a leap year if it is evenly divisible by 4.
Years that are divisible by 100 (century years such as 1900 or 2000) cannot be leap years unless they are also divisible by 400. (For this reason, the years 1700, 1800, and 1900 were not leap years, but the years 1600 and 2000 were.)
If a year satisfies both the rules above, then it is a leap year.
Checkout the flowchart for better visibility of implementation.
Lets start with coding :
year=int(input("Which year do you want to check?"))
(1). Take input from user and store it in year variable.
(2).NOTE - if-else are conditional statements used to check mutiple conditons and implement each basis on true else false.
(3). % : used to give remainder of the number
if year%4==0:
if year%100==0:
if year%400==0:
print("Leap year")
else:
print("Not leap year")
else:
print("Leap year")
else:
print(" Not leap year")
NOTE -
on every year that is evenly divisible by 4
except every year that is evenly divisible by 100
unless the year is also evenly divisible by 400
With these steps, we have successfully created a leap year program using python. That's it!
I hope you find it helpful.
You can find the copy of program on my github : https://github.com/Samra-qur/100-Days-Coding
Please connect with me on my LinkedIn : https://www.linkedin.com/in/samra-qureshi-a60828194/