[Solved] python 3.6 put number is str


I will suggest that you use nested/inner functions as shown below to solve you problem. This allows you to compute the result using integers, and then convert the result to a string, or any other type, before returning it.

def binary(n):
    def inner(m):  
        if m>0:   
            return inner(m//2)*10 + (m%2)
        else:    
            return 0
    return str(inner(n))

Alternatively you can cast n to the correct type whenever you use it. This is, in my opinion, a horrible to solve the problem, but it should still do the trick.

def binary(n):
    if int(n) > 0:
        return str(int(binary(n//2))*10 + n%2)
    else:
        return "0"

2

solved python 3.6 put number is str