Invalid Syntax Error - Average Calculator "IF" and "WHILE"
<p>I have no idea what I'm doing wrong, but this is driving me up a wall. Why am I getting a Syntax error? I have to code an average calculator using a while statement, where "0" defines that the program needs to perform the calculation.</p>

<p><a href="http://i.stack.imgur.com/umYUV.png" rel="nofollow"><img src="http://i.stack.imgur.com/umYUV.png" alt="enter image description here"></a>
Here's the sample output my professor defined:</p>

<pre><code>SAMPLE RUN 

Enter test score 80 

Enter test score 70 

Enter test score 90 

Enter test score 88 

Enter test score 0 

The average is 82.000%
</code></pre>

<p>The <code>if</code> statement in the image (please post the actual code in your question) is invalid. It needs a colon, i.e. <code>if test == '0':</code>. It also needs a body.</p>

<p>The sample output suggests that <code>0</code> is to terminate the loop. Check for that first, before you modify <code>division_integer</code> otherwise the average will be affected. Then, when you get a <code>0</code> <em>break</em> out of the while loop with <code>break</code>, i.e.</p>

<pre><code>while True:
    test = int(input('Enter test score:'))
    if test == 0:
        break
    addition_integer += test
    division_integer += 1
</code></pre>

<p>Note that you are converting the input into an integer, but your test was for the <em>string</em> <code>"0"</code>. You need to test for the integer <code>0</code> as I show above.</p>

<p>Another point, you should use a <code>try/except</code> block when converting the input into an integer so that you can catch invalid input:</p>

<pre><code>while True:
    try:
        test = int(input('Enter test score:'))
    except ValueError:
        print('Invalid number entered, try again.')
        continue
    # etc.
</code></pre>

python if-statement while-loop syntax-error average