so i have started the code, and i know that everything after the ‘else’ is probably wrong:
def binary(n):
if n < 2:
print (n)
else:
x = (bin(int(n)//2)
print (x)
it should do this recursively:
>>> binary(0)
0
>>> binary(1)
1
>>> binary(3)
11
>>> binary(9)
1001
i do need the function to print the binary representation rather than return.
This will not work as expected, as you have print in two places, you will end up with multiple lines, e.g.:
Other answers use strings, so here’s one with lists: 🙂
and if you really want a string, it’s as simple as this: 🙂
Of course, since you’ve already found out about the function bin, you should probably have done this in the first place:
How this reminds me of this:
Happy coding! 🙂