HELP plz [to determine leap year]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xGx
    New Member
    • Apr 2007
    • 1

    HELP plz [to determine leap year]

    Hi please could someone help. i have created this programming so you can work out if there is a LEAP YEAR. But i need it to handle centuries. heres the code

    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)
    Please can someone help me out sort it out. THANX
    Last edited by bartonc; Apr 4 '07, 05:49 PM. Reason: added [code][/code] tags
  • ilikepython
    Recognized Expert Contributor
    • Feb 2007
    • 844

    #2
    We can help but your code would be easier to understand if you use code tags around your code. See the posting guidelines for help with that.
    Repost your code and someone will help you

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by xGx
      Hi please could someone help. i have created this programming so you can work out if there is a LEAP YEAR. But i need it to handle centuries. heres the code

      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)
      Please can someone help me out sort it out. THANX
      Capital 'R' is messing you up.
      Code:
              Result = (year * 100) % 4

      Comment

      • hidrkannan
        New Member
        • Feb 2007
        • 32

        #4
        Originally posted by bartonc
        Capital 'R' is messing you up.
        Code:
                Result = (year * 100) % 4
        Code:
        Last2Digits = year % 100
        if (Last2Digits == 0):
            flag = year % 400
        else:
            flag = year % 4
        
        if (flag == 0):
            print " is a Leap year"
        else:
            print " is not a Leap year"

        Comment

        Working...