how to make if conditions work with specific string characters?
<p>I want to develop a program that takes input in the form of bits and outputs the decimal equivalent. </p>

<p>I am restricted in the kind of functions I can use so this is what I came up with:</p>

<pre><code>digits=raw_input("enter 1's and 0's")
a=len(digits)
repeat=a
c=0
total=0
while (c &lt; repeat):
    if digits[c]==1:
        total=total + (2**a)
        c=c+1
        a=a-1
    else:
        c=c+1
        a=a-1
print total
</code></pre>

<p>The code returns <code>0</code> for all kinds of strings I enter. </p>

<p>How can I fix my <code>if</code> statement to work correctly.</p>

<p><code>if 1==1</code> means if number 1 is equal 1</p>

<p><code>if "1"=="1"</code> means if string ("1") is equal "1"</p>

<p>You need to learn difference between data types.</p>

<pre><code>counter = 100          # An integer assignment
miles   = 1000.0       # A floating point
name    = "John"       # A string
</code></pre>

<hr>

<p>So, your code should look like this:</p>

<pre><code>digits=raw_input("enter 1's and 0's")
a=len(digits)
repeat=a
c=0
total=0
while (c &lt; repeat):
    if digits[c]=="1":
        total=total + (2**a)
        c=c+1
        a=a-1
    else:
        c=c+1
        a=a-1
print total
</code></pre>

python