![]() ![]() ![]() A solar year is the time it takes the Earth to complete its orbit around the Sun - about one year. The 365 days of the annual calendar are meant to match up with the solar year. ![]() Leap years are added to the calendar to keep it working properly. An extra day is added in a leap year-February 29 -which is called an intercalary day or a leap day. The Curious History of the Gregorian CalendarĢ016 is a leap year, which means that it has 366 days instead of the usual 365 days that an ordinary year has.(For example, 1700, 1800, and 1900 were not leap years, but 16, which are divisible by 400, were.) Related Links Exception: Century years are NOT leap years UNLESS they can be evenly divided by 400. (For example, 2016 divided by 4 = 504: Leap year!)Ģ. Most years that can be divided evenly by 4 are leap years. This was an exercise of mine to see if I could do so, and nothing more.įurther, be aware that ZeroDivisionErrors are a consequence of the input year equaling 0, and must be accounted for.įor example, a VERY basic timeit comparison of 1000 executions shows that, when compared against an equivalent codeblock utilizing simple if-statements and the modulus operator, this one-liner is roughly 5 times slower than its if-block equivalent.Why and when we have leap years Rules for Determining a Leap Yearġ. Please note: this code is horribly inefficient, incredibly unreadable, and a detriment to any code attempting to follow proper practices. If the year is a leap year this will result in True (or 1, if used in C), otherwise it will return False (or 0, if used in C). This value is compared against 0 with the less-than operator. This value is added to (y % 4), which will only be equal to 0 if the year is a leap year after accounting for the edge-cases.įinally, 1 is subtracted from this remaining value, resulting in -1 if the year is a leap year, and either 0, 1, or 2 if it is not. If it is divisible by both 100 and 400, it will result in 0. If the year is not divisible by 100, this will always equal 0, otherwise if it is divisible by 100, but not by 400, it will result in 1, 2, or 3. ((y % 400) / 100))) >Next, the year is divided by 400 (and subsequently 100, to return 1, 2, or 3 if it is not.Īre then multiplied together. If the year is evenly divisible by 100, this will result in a value of 1, otherwise it will result in a value of 0. (int((y - (y % 100)) / y) >It then accounts for those years divisible by 100. In this case the result is computed in the function add2_New() and no print statement, and returned to the caller who then prints it in turn. I would have just gotten the output of the print statement the result is: 15 without the None (which looks like what you are trying to do). Incidentally, if I had just called the add2() function simply with (note, no print statement): add2() The None from the print statement when I call the function add2() which does not have a return statement, causing the None to be printed. The first line comes form the print statement inside of add2(). Return n1 + n2 # returns the result to caller Print 'the result is:', n1 + n2 # prints but uses no *return* statement Some short examples regarding the above: def add2(n1, n2): Note: This does not address any possible problems you have with your leap year computation, but ANSWERS YOUR SPECIFIC QUESTION as to why you are getting None as a result of your function call in conjunction with your print. Or modify your function to return a value (by using the return statement), which then would be printed by your print statement. So either just call your function like this: leapyr(1900) Your function doesn't return anything, so that's why when you use it with the print statement you get None. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |