Adding numbers in a list gives TypeError: unsupported operand type(s) for +: 'int' and 'str'
<p>IÂ´m writing a simple calculator program that will let a user add a list of integers together as a kind of entry to the syntax of python. I want the program to allow the user to add as many numbers together as they want. My error is:</p>

<pre><code>Traceback (most recent call last):
  File "Calculator.py", line 17, in &lt;module&gt;
    addition = sum(inputs)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
</code></pre>

<p>My code is:</p>

<pre><code>#declare variables
inputs = []
done = False

#while loop for inputting numbers 
while done == False:
    value = raw_input()
#escape loop if user enters done
    if value == "Done":
        print inputs
        done = True
    else:
        inputs.append(value)

addition = sum(inputs)
print addition
</code></pre>

<p><a href="https://docs.python.org/2/library/functions.html#raw_input" rel="nofollow"><code>raw_input</code></a> returns strings, not numbers. <a href="https://docs.python.org/2/library/functions.html#sum" rel="nofollow"><code>sum</code></a> operates only on numbers.</p>

<p>You can convert each item to an int as you add it to the list: <code>inputs.append(int(value))</code>. If you use <code>float</code> rather than <code>int</code> then non-integer numbers will work too. In either case, this will produce an error if the user enters something that is neither <code>Done</code> nor an integer. You can use <code>try</code>/<code>except</code> to deal with that, but that's probably out of the scope of this question.</p>

python