#! /usr/bin/env python # def ch_to_digit ( c ): #*****************************************************************************80 # ## CH_TO_DIGIT returns the integer value of a base 10 digit. # # Example: # # C DIGIT # --- ----- # '0' 0 # '1' 1 # ... ... # '9' 9 # ' ' -1 # 'X' -1 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 05 June 2015 # # Author: # # John Burkardt # # Parameters: # # Input, character C, the decimal digit, '0' through '9' # are legal. # # Output, integer DIGIT, the corresponding integer value. If C was # 'illegal', then DIGIT is -1. # i0 = ord ( '0' ) i9 = ord ( '9' ) ic = ord ( c ) if ( i0 <= ic and ic <= i9 ): digit = ic - i0 else: digit = -1 return digit def ch_to_digit_test ( ): #*****************************************************************************80 # ## CH_TO_DIGIT_TEST tests CH_TO_DIGIT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 September 2015 # # Author: # # John Burkardt # import numpy as np import platform c_test = np.array ( [ '0', '1', '2', '3', '4', \ '5', '6', '7', '8', '9', \ 'X', '?', ' ' ] ) print ( '' ) print ( 'CH_TO_DIGIT_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' CH_TO_DIGIT: character -> decimal digit' ) print ( '' ) for i in range ( 0, 13 ): c = c_test[i] i2 = ch_to_digit ( c ) print ( ' %8d "%c" %8d' % ( i, c, i2 ) ) # # Terminate. # print ( '' ) print ( 'CH_TO_DIGIT_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) ch_to_digit_test ( ) timestamp ( )