Explicitly handle first digit and call recursive function countRec for remaining digits . Note that the first digit is considered as even digit
for i in range ( 1 , 10 ) : NEW_LINE INDENT ans += countRec ( digits + 1 , esum + i , osum , True , n ) NEW_LINE DEDENT return ans NEW_LINE