+ INFORMATION

Share on social networks!

Leap years in Python

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.

Screenshot 2021 10 18 at 12.27.40

Although there are several ways to do it, we have decided to use nested ifs to program our script. Let's see it. 

s4HROl 75uNGgT5Ib6YPaEcXcKUwMlW9gPAWauS1VlHGASgg3W8SUJdsb

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.

M39F7sHVsTN0RS 4AqBXJTM9MuZ2BONGm7cZq2rAcaQAoY7 4W8Bj5Dru5xqFyY020cSWuF1YJwygnGFd4BjnPLj9phzhLA c9L5Zss5oup OFPxcD7s9YrN RaQZRTrL7VVMohO7maEp7FE8Q=s 0

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.

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SAU as the party responsible for this website. The purpose of collecting and processing personal data is to manage your subscription to the newsletter as well as to send commercial information about the services of the data controller. The legitimacy is the explicit consent of the interested party. Data will not be transferred to third parties, except under legal obligation. You may exercise your rights of access, rectification, limitation and deletion of data at compliance@grupomainjobs.com, as well as the right to lodge a complaint with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find on our website.
marter-in-python

Leave a comment

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SAU as the party responsible for this website. The purpose of collecting and processing personal data is to manage your subscription to the newsletter as well as to send commercial information about the services of the data controller. The legitimacy is the explicit consent of the interested party. Data will not be transferred to third parties, except under legal obligation. You may exercise your rights of access, rectification, limitation and deletion of data at compliance@grupomainjobs.com, as well as the right to lodge a complaint with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find on our website.