Program to add together a series of number
<blockquote>
  <p>I am writing a program that will add together a series of
  numbers a user inputs until the user enters a rogue value of 0. The
  program will then display the total.</p>
</blockquote>

<pre><code>user_input = None
total_sum = 0
while user_input != 0:
    user_input = input("Enter a number:")
    total_sum = total_sum + user_input 

# Sample output:
# Enter a number: 5
# Enter a number: 50
# Enter a number: 10
# Enter a number: 0
# The total sum of the numbers are 65
print("The total sum of the numbers are {}".format(total_sum))
</code></pre>

<p>The error that keeps coming up is :</p>

<pre><code>total_sum = total_sum + user_input
TypeError: unsupported operand type(s) for +: 'int' and 'str'
</code></pre>

<p>input("Enter a number") returns a string which means user_input is of type string.
So you need to cast user_input to int in order to add. i.e. <code>total_sum = total_sum + parseInt(user_input)</code></p>

python python-3.x loops