human
Largest number less than N with digit sum greater than the digit sum of N | Function to return the sum of the digits of n.
Loop for each digit of the number.
Function to return the greatest number less than n such that the sum of its digits is greater than the sum of the digits of n.
Starting from n - 1.
Check until 1.
If i satisfies the given condition.
If the condition is not satisfied.
Driver code"
How can the above be solved in Python?
 Give me a code to largest number less than N with digit sum greater than the digit sum of N and the other steps required?
assistant
#Here is code to largest number less than N with digit sum greater than the digit sum of N and the other steps required.
 def sumOfDigits ( n ) :
	res = 0 ;
	while ( n > 0 ) :
		res += n % 10
		n /= 10
	return res ;
def findNumber ( n ) :
	i = n - 1 ;
	while ( i > 0 ) :
		if ( sumOfDigits ( i ) > sumOfDigits ( n ) ) :
			return i
		i -= 1
	return - 1 ;
if __name__ == " _ _ main _ _ " :
	n = 824 ;
	print ( findNumber ( n ) )