Today we are going to make a small script which will tell us if the year we are asking about is a leap year or not.
Script for leap years
We can know if a year is a leap year if this is multiple of 4. If it is also a multiple of 100, it will not be a leap year (keep in mind that 100 is a multiple of 4 and therefore any number that is a multiple of 100 is also a multiple of 4) unless it is a multiple of 400, which will be a leap year.
We leave you a table so you can see it more easily.
Although there are several ways to do it, we have decided to use nested ifs to program our script. Let's see it.
Since we are pytho programmersn, we can use the function isleap which includes the calendar module Python. It's as simple as I show you below.
This way the code is much cleaner and more professional.
If, like us, you are passionate about programming and can't stop learning, we invite you to discover our Master in Advanced Programming in Python for Big Data, Hacking and Machine Learning, where in just 12 months you will become a qualified expert with extensive knowledge in Big Data, Hacking and Machine Learning.