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>Alternative answer </p>

<p>Use a list, sum and divide. Same concept, compare test inside the while loop in order to break out of it. Also check if you get valid input that can be made an integer with a try/except. </p>

<p>Additionally, beware of the division by zero </p>

<pre><code>values = [] 

while True:
    try:
        test = int(input('Enter test score:'))
        if test == 0:
            break
        values.append(test) 
    except:
        break

total = len(values)
avg = 0 if total == 0 else 1.0 * sum(values) / total 

print("The average is", avg) 
</code></pre>

python if-statement while-loop syntax-error average