0
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

Alexis
  • 41
  • 4

1 Answers1

1

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)
user2390182
  • 72,016
  • 6
  • 67
  • 89