human
Perform n steps to convert every digit of a number in the format [ count ] [ digit ] | Function to perform every step.
perform N steps.
Traverse in the string.
for last digit.
recur for current string.
Driver Code"
How can the above be solved in Python?
 Give me a code to perform n steps to convert every digit of a number in the format [ count ] [ digit ] and the other steps required?
assistant
#Here is code to perform n steps to convert every digit of a number in the format [ count ] [ digit ] and the other steps required.
 def countDigits ( st , n ) :
	if ( n > 0 ) :
		cnt = 1
		i = 0
		st2 = " "
		i = 1
		while ( i < len ( st ) ) :
			if ( st [ i ] == st [ i - 1 ] ) :
				cnt = cnt + 1
			else :
				st2 += chr ( 48 + cnt )
				st2 += st [ i - 1 ]
				cnt = 1
			i = i + 1
		st2 += chr ( 48 + cnt )
		st2 += st [ i - 1 ]
		countDigits ( st2 , n - 1 )
		n = n - 1 ;
	else :
		print ( st )
num = "123"
n = 3
countDigits ( num , n )