all, I have this code that, for the life of me, I can't figure out how to solve this TypeError.
def dtobr(n):
if n == 0:
return 0
else:
return (n % 2) + 10 * dtobr(int(n / 2))
I need it to return as a string (project requirement for class). The math is correct, but when I change the last line to
return str((n % 2) + 10 * dtobr(int(n / 2)))
I get
"TypeError: unsupported operand type(s) for +: 'int' and 'str'".
I have tried setting "return (n % 2) + 10 * dtobr(int(n / 2))" to x, setting y to int(x) and returning y, and I've have no clue (and Google isn't offering any solutions that I can try to apply to my problem) what else I can do. Any ideas would be helpful!!
dtobron the result ofdtobr, and it multiplies with an int.