So my problem is this i have an number like 123 and as the tilte sugests i want the result to be 13.
The problem is that firstly with the method im using im going to get
Look at the operation on last line, you are getting the last digit if it is odd and then multiplying it with 10 and adding it to recursion result of next call, I believe that is why it is not working, try the code below, here you are appending the last digit at end always so final number comes in correct order.
def apenas_digitos_impares(n):
if n == 0:
return 0
elif (n % 10) % 2 == 0:
return apenas_digitos_impares(n // 10)
elif (n % 10) % 2 == 1:
return 10 * apenas_digitos_impares(n // 10) + (n % 10)