#! /usr/bin/env python # def year_is_leap_gregorian ( y ): #*****************************************************************************80 # ## YEAR_IS_LEAP_GREGORIAN returns TRUE if the Gregorian year was a leap year. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 August 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer Y, the year to be checked. # # Output, bool YEAR_IS_LEAP_GREGORIAN, TRUE if the year was a leap year, # FALSE otherwise. # from sys import exit if ( y <= 0 ): print ( '' ) print ( 'YEAR_IS_LEAP_GREGORIAN - Fatal error!' ) print ( ' This function will not accept nonpositive years.' ) exit ( 'YEAR_IS_LEAP_GREGORIAN - Fatal error!' ) if ( ( y % 400 ) == 0 ): value = True elif ( ( y % 100 ) == 0 ): value = False elif ( ( y % 4 ) == 0 ): value = True else: value = False return value def year_is_leap_gregorian_test ( ): #*****************************************************************************80 # ## YEAR_IS_LEAP_GREGORIAN_TEST tests YEAR_IS_LEAP_GREGORIAN. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 August 2015 # # Author: # # John Burkardt # import platform from i4_uniform_ab import i4_uniform_ab print ( '' ) print ( 'YEAR_IS_LEAP_GREGORIAN_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Report leap years in the Gregorian calendar.' ) print ( '' ) print ( ' Year Leap?' ) print ( '' ) seed = 123456789 for i in range ( 0, 20 ): y, seed = i4_uniform_ab ( 1, 2100, seed ) is_leap = year_is_leap_gregorian ( y ) print ( ' %4d %s' % ( y, is_leap ) ) # # Terminate. # print ( '' ) print ( 'YEAR_IS_LEAP_GREGORIAN_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) year_is_leap_gregorian_test ( ) timestamp ( )