human
Write me a code to nambiar Number Generator and the other steps required given the following:
Nambiar Number Generator | Function to return the Nambiar number of the given number.
If there is no digit to choose.
Choose the first digit.
Chosen digit 's parity.
To store the sum of the consecutive digits starting from the chosen digit.
While there are digits to choose.
Update the sum.
If the parity differs.
Return the current sum concatenated with the Numbiar number for the rest of the String.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to nambiar Number Generator and the other steps required.
 def nambiarNumber ( Str , i ) :
	if ( i >= len ( Str ) ) :
		return " "
	firstDigit = ord ( Str [ i ] ) - ord ( '0' )
	digitParity = firstDigit % 2
	sumDigits = 0
	while ( i < len ( Str ) ) :
		sumDigits += ( ord ( Str [ i ] ) - ord ( '0' ) )
		sumParity = sumDigits % 2
		if ( digitParity != sumParity ) :
			break
		i += 1
	return ( " " + str ( sumDigits ) + nambiarNumber ( Str , i + 1 ) )
Str = "9880127431"
print ( nambiarNumber ( Str , 0 ) )