I'm doing decimal to binary using recursion method. However, I was unable to convert it to string using the code below. Any help? <3
def to_binary(d):
if d == 0:
return str(0)
else:
return str(d % 2 + 10 * to_binary(int(d // 2)))
result = to_binary(nums)
print("Result: " + result)
It's always giving errors:
- unsupported operand type(s) for +: 'int' and 'str'
Updated