def binary(val):
return str(val) if val<=1 else binary(val>>1) + str(val&1)
how can I rewrite this code
i Have tried:
if (val<=1) :
return str(val)
else
binary(val>>1) + str(val)
but it does not work
def binary(val):
return str(val) if val<=1 else binary(val>>1) + str(val&1)
how can I rewrite this code
i Have tried:
if (val<=1) :
return str(val)
else
binary(val>>1) + str(val)
but it does not work
You are missing the 'return'
, a colon ':'
, '&1'
. And that is not considering the indentation:
if val <= 1:
return str(val)
else:
return binary(val >> 1) + str(val & 1)