Python user input for def function
<p>How to do a number input by user first then only display the answer?</p>

<pre><code>a = int(raw_input("Enter number: "),twoscomp)

def tobin(x, count = 8):
    return "".join(map(lambda y:str((x&gt;&gt;y)&amp;1), range(count-1, -1, -1)))

def twoscomp(bin_str):
    return tobin(-int(bin_str,2),len(bin_str))

print a
</code></pre>

<p>I believe this is what you're trying to do?</p>

<pre><code>def tobin(x, count = 8):
    return "".join(map(lambda y:str((x&gt;&gt;y)&amp;1), range(count-1, -1, -1)))

def twoscomp(bin_str):
    return tobin(-int(bin_str,2),len(bin_str))

a = twoscomp(raw_input("Enter number: "))

print a
</code></pre>

<p>Things to note: </p>

<ul>
<li>You need to define things before you use them, and that includes functions. </li>
<li>Indentation is important, and you should use it.</li>
</ul>

python bit-manipulation twos-complement