![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: May 2007
Posts: 2
OS: Windows XP Pro
|
Hey, i got this code to work out whether or not it is a leap year, i defined it in a module.
def leapyear(year): ret = 0 if(year % 1000): ret = 1 elif(year % 400): ret = 1 elif(year % 4): ret = 1 if (ret == 1): isleapyear = "Yes it is a leap year" elif (ret == 0): isleapyear = "No it is not a leap year" return isleapyear Now when i run it, inputting 4 as the year var makes it say correctly it is a leap year, as does 8,12,16 etc etc. However, when i input 1000 or something around there, it says it is NOT a leap year. Anyone know why? Cheers |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Roaming To Help
Join Date: Nov 2006
Posts: 5,642
OS: Many
|
I don't know much of Python, but a friend I visited was using this script for what you're wanting to do:
Code:
def isLeapYear (year):
result = year % 4
if result > 0:
print "It is NOT a leap year"
else:
print "It IS a leap year"
result = (year * 100) % 4
if result >0:
print "It is NOT a leap year"
isLeapYear(400)
isLeapYear(800)
isLeapYear(1600)
isLeapYear(1601)
isLeapYear(2004)
isLeapYear(2012)
isLeapYear(3010)
isLeapYear(3330)
![]() Maybe it will be of some help. |
|
|
|
|
|
#3 (permalink) | |
|
Mentor, Analyst - Security Team
Join Date: May 2006
Location: Oregon
Posts: 2,503
OS: MacOS X, Debian, OpenBSD, Windows
|
Re: Python 2.5 Help
I believe the leap year formula for the Gregorian calendar (post-1582) is:
Quote:
__________________
The chance to begin again in a golden land of opportunity and adventure. Need HijackThis help? Please read MicroBell's Five Step Process before posting.
Please donate and help keep this site free to all. ![]() UNITE/ASAP: Proud member since 2006 |
|
|
|
|
![]() |
| Thread Tools | |
|
|