#! /usr/bin/env python # def isbn_digit_to_i4 ( c ): #*****************************************************************************80 # ## ISBN_DIGIT_TO_I4 converts an ISBN digit to an I4. # # Discussion: # # The characters '0' through '9' stand for themselves, but # the character 'X' or 'x' stands for 10. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 September 2015 # # Author: # # John Burkardt # # Parameters: # # Input, character C, the ISBN character code to be converted. # # Output, integer VALUE, the numeric value of the character # code, between 0 and 10. This value is returned as -1 if C is # not a valid character code. # if ( c == '0' ): value = 0 elif ( c == '1' ): value = 1 elif ( c == '2' ): value = 2 elif ( c == '3' ): value = 3 elif ( c == '4' ): value = 4 elif ( c == '5' ): value = 5 elif ( c == '6' ): value = 6 elif ( c == '7' ): value = 7 elif ( c == '8' ): value = 8 elif ( c == '9' ): value = 9 elif ( c == 'X' or c == 'x' ): value = 10 else: value = -1 return value def isbn_digit_to_i4_test ( ): #*****************************************************************************80 # ## ISBN_DIGIT_TO_I4_TEST tests ISBN_DIGIT_TO_I4. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 16 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', 'x', 'Y', '*', '?', \ ' ' ] ) print ( '' ) print ( 'ISBN_DIGIT_TO_I4_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' ISBN_DIGIT_TO_I4 converts an ISBN digit to an I4' ) print ( '' ) for i in range ( 0, 16 ): c = c_test[i] i4 = isbn_digit_to_i4 ( c ) print ( ' "%c" %2d' % ( c, i4 ) ) # # Terminate. # print ( '' ) print ( 'ISBN_DIGIT_TO_I4_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) isbn_digit_to_i4_test ( ) timestamp ( )