human
Can you provide a code to program to check for ISBN and the other steps required given the following:
Program to check for ISBN | Python code to check if a given ISBN is valid or not ..
check for length.
Computing weighted sum of first 9 digits.
Checking last digit.
If last digit is ' X ' , add 10 to sum , else add its value ..
Return true if weighted sum of digits is divisible by 11.
Driver Code"
Solution in Python:
assistant
#Here is code to program to check for ISBN and the other steps required.
 def isValidISBN ( isbn ) :
	if len ( isbn ) != 10 :
		return False
	_sum = 0
	for i in range ( 9 ) :
		if 0 <= int ( isbn [ i ] ) <= 9 :
			_sum += int ( isbn [ i ] ) * ( 10 - i )
		else :
			return False
	if ( isbn [ 9 ] != ' X ' and 0 <= int ( isbn [ 9 ] ) <= 9 ) :
		return False
	_sum += 10 if isbn [ 9 ] == ' X ' else int ( isbn [ 9 ] )
	return ( _sum % 11 == 0 )
isbn = "007462542X "
if isValidISBN ( isbn ) :
	print ( ' Valid ' )
else :
	print ( " Invalid " )