getting only the odd digits in a number with recursion

后端 未结 3 1458
谎友^
谎友^ 2021-01-22 01:08

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

3条回答
  •  后悔当初
    2021-01-22 02:05

    I mean, if python is where you want the solution just do;

    Def pluck_even_digits(N):
        str_N = str(abs(N))
    
        for digit in [ 0, 2, 4, 6, 8]:
            str_N.replace( str(digit), “”)
    
        Return int(str_N)
    

    It’s python, you are not restricted to just use pure math. Also, this way allows you to easily choose a base that is not 10 and pluck values from the representation in that new base.

提交回复
热议问题