human
Can you provide a code to check if a large number is divisible by 13 or not and the other steps required given the following:
Check if a large number is divisible by 13 or not | Returns true if number is divisible by 13 else returns false.
Append required 0 s at the beginning ..
Same as strcat ( num , "00" ).
in c ..
Same as strcat ( num , "0" ).
in c ..
Alternatively add / subtract digits in group of three to result ..
Store group of three numbers in group variable ..
Generate alternate series of plus and minus.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if a large number is divisible by 13 or not and the other steps required.
 def checkDivisibility ( num ) :
	length = len ( num )
	if ( length == 1 and num [ 0 ] == '0' ) :
		return True
	if ( length % 3 == 1 ) :
		num = str ( num ) + "00"
		length += 2
	elif ( length % 3 == 2 ) :
		num = str ( num ) + "0"
		length += 1
	sum = 0
	p = 1
	for i in range ( length - 1 , - 1 , - 1 ) :
		group = 0
		group += ord ( num [ i ] ) - ord ( '0' )
		i -= 1
		group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10
		i -= 1
		group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100
		sum = sum + group * p
		p *= ( - 1 )
	sum = abs ( sum )
	return ( sum % 13 == 0 )
if __name__ == " _ _ main _ _ " :
	number = "83959092724"
	if ( checkDivisibility ( number ) ) :
		print ( number , " is ▁ divisible ▁ by ▁ 13 . " )
	else :
		print ( number , " is ▁ not ▁ divisible ▁ by ▁ 13 . " )