How to add an unspecified amount of variables together?
<p>I'm trying to add in python 3.5.2 but I have an unspecified amount of variables. I have to use very basic functions; I can't use <code>list</code>. I can't figure out how I'm supposed to add each new variable together without a <code>list</code>. When I run the code it adds the last entered <code>price1</code> which is <code>-1</code>. I need to use the <code>-1</code> to tell the program to total all the variables. </p>

<pre><code>count = 0

while (True):

     price1 = int( input("Enter the price of item, or enter -1 to get total: "))

     count += 1

     if (price1 ==-1):
         subtotal = (price1 + ) #this is where I"m having trouble
                                #at least I think this is the problem
         tax = (subtotal*0.05)
         total = (subtotal + tax)

         print("Subtotal: .  .  . . . ", subtotal)
         print("Tax: . .  . . . . . . ", tax)
         print("Total: . . . . . . . .", total)

         break
</code></pre>

<p>You almost had it. Looking at your code, what I would suggest you do is create a <code>subtotal</code> variable just outside of your loop and initialize it to <code>0</code>. Furthermore, you are not using <code>count</code> for anything, so get rid of that.</p>

<p>When you get your <code>price</code> input, check it right after for the <code>-1</code> condition. If you have a <code>-1</code> value, then proceed with your <em>math</em>, otherwise your <code>else</code> will start running the <code>subtotal</code> with the <code>subtotal += price</code>.</p>

<p>So, you should have something like:</p>

<pre><code>subtotal = 0
while (True):

     price = int( input("Enter the price of item, or enter -1 to get total: "))

     if price == -1:
         tax = subtotal*0.05
         total = subtotal + tax

         print("Subtotal: .  .  . . . ", subtotal)
         print("Tax: . .  . . . . . . ", tax)
         print("Total: . . . . . . . .", total)

         break
     else:
         subtotal += price
</code></pre>

python python-2.7 python-3.x