You pass the line to bin() :
>>> bin('10') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object cannot be interpreted as an index
Instead, give it an integer:
>>> bin(10) '0b1010'
turning the result of raw_input() into int() :
n = int(raw_input())
Tip. You can easily change the line by giving it a negative step in the fragment:
>>> 'forward'[::-1] 'drawrof'
to simplify your function:
def reversebinary(): n = int(raw_input()) bin_n = bin(n)[2:] revbin = bin_n[::-1] return int(revbin, 2)
or even:
def reversebinary(): n = int(raw_input()) return int(bin(n)[:1:-1], 2)
source share