{"id":46226,"date":"2021-10-18T12:45:56","date_gmt":"2021-10-18T10:45:56","guid":{"rendered":"https:\/\/eiposgrados.com\/?p=46226"},"modified":"2021-10-29T16:50:46","modified_gmt":"2021-10-29T14:50:46","slug":"leap-years-in-python","status":"publish","type":"post","link":"https:\/\/eiposgrados.com\/eng\/blog-python\/anos-bisiestos-en-python\/","title":{"rendered":"Leap years in Python"},"content":{"rendered":"<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Script for leap years <\/h2>\n\n\n\n<p>We can know if a year is a leap year if this is <strong>multiple of 4<\/strong>. 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.<\/p>\n\n\n\n<p>We leave you a table so you can see it more easily.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/eiposgrados.com\/wp-content\/uploads\/2021\/10\/Captura-de-pantalla-2021-10-18-a-las-12.27.40-1024x343.png\" alt=\"\" class=\"wp-image-46227\" width=\"512\" height=\"172\" title=\"\"><\/figure><\/div>\n\n\n\n<p>Although there are several ways to do it, we have decided to use nested ifs to program our script. Let&#039;s see it.&nbsp;<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"100%\" src=\"https:\/\/lh3.googleusercontent.com\/s4HROl-75uNGgT5Ib6YPaEcXcKUwMlW9gPAWauS1VlHGASgg3W8SUJdsb-KM_vzaiUNF9fxUmStwM1j1wbu2BM6KER8ovW_01Hw6djuSCO445yXxPwJKY50OEXOiVhWVNS_cXOkosY5_CHh66g=s0\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>Since we are <strong>pytho programmers<\/strong>n, we can use the function <strong><em>isleap<\/em><\/strong> which includes the <strong>calendar module<\/strong> <strong>Python<\/strong>. It&#039;s as simple as I show you below.<\/p>\n\n\n\n<p><img decoding=\"async\" width=\"100%\" src=\"https:\/\/lh6.googleusercontent.com\/M39F7sHVsTN0RS-4AqBXJTM9MuZ2BONGm7cZq2rAcaQAoY7_4W8Bj5Dru5xqFyY020cSWuF1YJwygnGFd4BjnPLj9phzhLA_c9L5Zss5oup-OFPxcD7s9YrN-RaQZRTrL7VVMohO7maEp7FE8Q=s0\" alt=\"\" title=\"\"><\/p>\n\n\n\n<p>This way the code is much cleaner and more professional.<\/p>\n\n\n\n<p>If, like us, you are passionate about programming and can&#039;t stop learning, we invite you to discover our <a href=\"https:\/\/eiposgrados.com\/eng\/master-in-python\/\">Master in Advanced Programming in Python for Big Data, Hacking and Machine Learning<\/a><strong>, where in just 12 months you will become a qualified expert with extensive knowledge in Big Data, Hacking and Machine Learning.<\/strong><\/p>","protected":false},"excerpt":{"rendered":"<p>Continue learning about Python programming: developing a leap year script. These are the steps.<\/p>","protected":false},"author":1,"featured_media":51495,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[407],"tags":[],"class_list":["post-46226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/46226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/comments?post=46226"}],"version-history":[{"count":0,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/46226\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media\/51495"}],"wp:attachment":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media?parent=46226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/categories?post=46226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/tags?post=46226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}