human
Give me a code to check if a number is jumbled or not and the other steps required given the following:
Check if a number is jumbled or not | Function to check if a number is jumbled or not.
Single digit number.
Checking every digit through a loop.
All digits were checked.
Digit at index i.
Digit at index i - 1.
If difference is greater than 1.
Number checked.
- 1234 to be checked.
- 1247 to be checked"
How can the above be solved in Python?
assistant
#Here is code to check if a number is jumbled or not and the other steps required.
 def checkJumbled ( num ) :
	if ( num / 10 == 0 ) :
		return True
	while ( num != 0 ) :
		if ( num / 10 == 0 ) :
			return True
		digit1 = num % 10
		digit2 = ( num / 10 ) % 10
		if ( abs ( digit2 - digit1 ) > 1 ) :
			return False
		num = num / 10
	return True
num = - 1234
if ( checkJumbled ( abs ( num ) ) ) :
	print " True ▁ "
else :
	print " False "
num = - 1247
if ( checkJumbled ( abs ( num ) ) ) :
	print " True ▁ "
else :
	print " False "