#! /usr/bin/env python # def bank_is_valid ( s ): #*****************************************************************************80 # ## BANK_IS_VALID reports whether a bank checksum is valid. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 October 2015 # # Author: # # John Burkardt # # Parameters: # # Input, string S, a string containing 9 digits. # Dashes and other characters will be ignored. # # Output, bool VALUE, is TRUE if the string is valid. # from s_to_digits import s_to_digits from bank_check_digit_calculate import bank_check_digit_calculate n = 9 dvec = s_to_digits ( s, n ) d1 = bank_check_digit_calculate ( s ) d2 = dvec[8] if ( d1 == d2 ): value = True else: value = False return value def bank_is_valid_test ( ): #*****************************************************************************80 # ## BANK_IS_VALID_TEST tests BANK_IS_VALID. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 October 2015 # # Author: # # John Burkardt # import platform print ( '' ) print ( 'BANK_IS_VALID_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' BANK_IS_VALID reports whether a bank checksum is valid.' ) print ( '' ) # # Supply a valid code code, with dashes. # s1 = '323-371-076' value1 = 1 value2 = bank_is_valid ( s1 ) print ( ' Validity of "%s" is %d, expecting %d' % ( s1, value2, value1 ) ) # # Modify one digit. # s1 = '323-371-576' value1 = 0 value2 = bank_is_valid ( s1 ) print ( ' Validity of "%s" is %d, expecting %d' % ( s1, value2, value1 ) ) # # Supply a valid code, with spaces. # s1 = '123 456 780' value1 = 1 value2 = bank_is_valid ( s1 ) print ( ' Validity of "%s" is %d, expecting %d' % ( s1, value2, value1 ) ) # # Modify the check digit. # s1 = '123 456 789' value1 = 0 value2 = bank_is_valid ( s1 ) print ( ' Validity of "%s" is %d, expecting %d' % ( s1, value2, value1 ) ) # # Terminate. # print ( '' ) print ( 'BANK_IS_VALID_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) bank_is_valid_test ( ) timestamp ( )