|
[Python] Leap year finder
|
|
03-14-2010, 06:52 AM
Post: #1
|
|||
|
|||
|
[Python] Leap year finder
From: "http://www.openbookproject.net/pybiblio/practice/wilson/"
Description Leap years occur according to the following formula: a leap year is divisible by four, but not by one hundred, unless it is divisible by four hundred. For example, 1992, 1996, and 2000 are leap years, but 1993 and 1900 are not. The next leap year that falls on a century will be 2400. Input Your program should take a year as input. Output Your program should print whether the year is or is not a leap year. Sample Session What year: 1999 1999 is not a leap year. What year: 1988 1988 is a leap year. Code: y=int(raw_input("What year: "))Code: while (True):
![]()
|
|||
|
03-14-2010, 07:02 AM
Post: #2
|
|||
|
|||
|
RE: [Python] Leap year finder
Very good task. I was dong this leap year tasks, and they are interesting.
Also one description for leap years (at least last 20) is that Leap year is the one in which Olympic Games were held LOL There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
03-14-2010, 02:29 PM
Post: #3
|
|||
|
|||
|
RE: [Python] Leap year finder
yeah I was also doing those tasks using C++.
nice source btw. |
|||
|
03-14-2010, 02:57 PM
Post: #4
|
|||
|
|||
|
RE: [Python] Leap year finder
You can use the built in function also.
Code: import calendar;I don't have a compiler on this computer because im not on my system, but if I remember correctly it goes something like that
|
|||
|
03-15-2010, 01:08 AM
Post: #5
|
|||
|
|||
|
RE: [Python] Leap year finder
Somehow I completely forgot about C++. Didn't work in it for months. Well, not that I'm good in it, but it would be nice if I do some tasks in c++ from time to time.
I don't know many built in functions. Maybe I should dedicate some more time to find some interesting functions.
![]()
|
|||
|
05-14-2010, 10:14 AM
(This post was last modified: 05-14-2010 10:17 AM by Rich69.)
Post: #6
|
|||
|
|||
RE: [Python] Leap year finder
(03-14-2010 06:52 AM)Alphablend Wrote: From: "http://www.openbookproject.net/pybiblio/practice/wilson/" Hey dude, not to take the wind out of your sails or anything but i noticed what i think is a problem with your code. A leap year as said is a year that can be divided by 4 but not 100 UNLESS it can be divided by 400 right? (I'll look such an idiot if i've got this wrong). Anyway the year 1000 is NOT leap year based on these rules, it can't be divided by 400 but can be divided by 100. However if you run your program and enter 1000 is spits out that it is a leap year. Now this isn't an actual forumla issue here either because you have the formula's corret, i think. It might just be a typo on the Code: elif y%100==0:line I'm doing the same task myself as part of my University course work lol. I got: Code: def LeapYear(year):A very raw and basic output i know but i just care about getting my head around the formula's at the moment. Rich P.S Sorry about posting in a 2 month old thread. My bad |
|||
|
05-14-2010, 12:56 PM
Post: #7
|
|||
|
|||
|
RE: [Python] Leap year finder
Ah thanks for the reply Rich. Reviving threads really isn't a bad thing here...If you find a problem with the thread, it's better to point it out, to be corrected. Then to leave this thread with incorrect information.
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
05-15-2010, 01:29 AM
Post: #8
|
|||
|
|||
|
RE: [Python] Leap year finder
I think that you are right Rich69.
Leap year can be divided with 4. If you can divide it with 100 than you need to divide it with 400 to be sure it is leap. 1900 is not a leap year (but it can be divided with 100 but not with 400) 2000 is a leap year (it but it can be divided with 100 and 400) There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
11-02-2010, 05:52 AM
(This post was last modified: 11-02-2010 05:53 AM by Alphablend.)
Post: #9
|
|||
|
|||
|
RE: [Python] Leap year finder
Wow, yeah. My bad. Thanks for correcting my code.
![]()
|
|||
|
11-02-2010, 10:40 PM
(This post was last modified: 01-21-2011 07:37 PM by codecaine.)
Post: #10
|
|||
|
|||
|
RE: [Python] Leap year finder
Since python is a script language you can view all it's source code. Here is how they did their function. This code is located in calendar.py
Code: def isleap(year): |
|||
|
« Next Oldest | Next Newest »
|




![[Image: 45669_pythonlogo.png]](http://myph.us/pics/45669_pythonlogo.png)


