+ 1
Can someone explain to me why it returns them in binaries?
def convert(num): if num == 0: return 0 else: return (num % 2 + 10 * convert(num // 2)) a = int(input()) print(convert(a))
2 Answers
+ 1
Recursive base transformation is not a easy topic, you better try to calculate it by hand and write it down on a paper.
Lastly, the result is only resemble a binary by an integer, not a true binary.
+ 1
This is code for converting a integer to binary equalent.
ex:
2 => 0 + 10*( 1+10*(0) ) = 10
3 => 1 + 10*( 1+10*(0) ) = 11