Public feed #727500

Anonymous

public python v1 · immutable
Raw Edit
·published 2007-10-06 02:09 UTC
rendered paste body
def verify_isbn(isbn):    '''verify_isbn(str) - > boolean        Returns True if the string argument entered, isbn, is a valid isbn.     Otherwise returns False. Also returns False if the argument is not a string or    if the string entered is not the appropriate length.'''        if ( type(isbn) != str ):        return False    if ( len(isbn) != 13 ) :        return False        count = -1    sum = 0    for digit in isbn:        if (digit != '-' and count < 8 ):#Ensures that neither -'s nor the             #checksum are included in any calculations            count += 1 #Updates the value count so that it matches the position            #of each digit in the isbn.            sum += int(digit) * (10 - count)    sum = 11 - (sum % 11)    sum = sum % 11        if ( sum < 10 ):               return str(sum) == isbn[12] #Checks to see whether the calculated value    #and the checksum are equivalent.        elif ( sum == 10 ):                return 'X' == isbn[12] #Handles the special case where the checksum is X    #and not a single digit number.