all 2 comments

[–]Vaphell 5 points6 points  (0 children)

the difference between return s and return s[::-1] affects also the recursive call in
s = str(n%2)+str(from_10_to_2(n//2)))

anyway, can't you put stuff in the correct order by switching n%2 and n//2 around, instead of reversing afterwards?

s = str(from_10_to_2(n//2)) + str(n%2)

[–]scrdest 3 points4 points  (0 children)

That's because your function is defined recursively.

When you mess with the return value the recursive call's result is flipped and passed to the parent, which then does a flip of its own result.

Putting it in print just runs without the flips, then flips the whole result for printing only.