human
What is a code to stepping Numbers and the other steps required given the following:
Stepping Numbers | This function checks if an integer n is a Stepping Number.
Initalize prevDigit with - 1.
Iterate through all digits of n and compare difference between value of previous and current digits.
Get Current digit.
Single digit is consider as a Stepping Number.
Check if absolute difference between prev digit and current digit is 1.
A brute force approach based function to find all stepping numbers ..
Iterate through all the numbers from [ N , M ] and check if its a stepping number ..
Driver code.
Display Stepping Numbers in the range [ n , m ]"
How can the above be solved in Python?
assistant
#Here is code to stepping Numbers and the other steps required.
 def isStepNum ( n ) :
	prevDigit = - 1
	while ( n ) :
		curDigit = n % 10
		if ( prevDigit == - 1 ) :
			prevDigit = curDigit
		else :
			if ( abs ( prevDigit - curDigit ) != 1 ) :
				return False
		prevDigit = curDigit
		n //= 10
	return True
def displaySteppingNumbers ( n , m ) :
	for i in range ( n , m + 1 ) :
		if ( isStepNum ( i ) ) :
			print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	n , m = 0 , 21
	displaySteppingNumbers ( n , m )