I tried to convert a decimal number to binary using recursion and at the end it is supposed to return the list that is holding the digits of binary number. But instead of returning that list it returns None. But when I tried to print the list in recursive function, it prints the list correctly. Can someone point out what am I doing wrong here?
def binary_rec(n, l=[]):
if n>=1:
r = n%2
l.append(r)
binary_rec(n//2, l)
else:
print(sorted(l,reverse=True))
l_rev = sorted(l,reverse=True)
#ll = l.copy()
#print('I am ll')
#print(ll)
#return ll
return l_rev
if __name__ == '__main__':
import sys
inp = sys.argv[1]
x = binary_rec(int(inp),l=[])
print(x)