Recursion Decimal to binary | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Recursion Decimal to binary

How can i make this code right to convert decimal to binary. NB: Without changing the third line! https://code.sololearn.com/cr0Haqu5ePUF/?ref=app

7th Aug 2021, 7:52 AM
sid
sid - avatar
1 Answer
+ 10
You're just missing the base case. def convert(num): if num>=1: return (num % 2 + 10 * convert(num // 2)) return num print(convert(int(input())))
7th Aug 2021, 8:00 AM
Hatsy Rei
Hatsy Rei - avatar