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>I've fixed your code for you. For future questions, please post your code directly in your question and indent it all by 4 spaces to properly format it.    </p>

<pre><code>addition_integer = 0
divison_integer = 0

while True:
    test = int(input("Enter test score: "))
    if test == 0:
        break
    else:
        addition_integer += test
        divison_integer += 1

print("The average is {}%".format(addition_integer/divison_integer))
</code></pre>

<p>Here's an explanation of what I did to fix this:</p>

<p>You were looping <code>while True</code>, which is correct, however you had no way to break out of the while loop. Your line saying <code>if test == '0'</code> would never resolve to true because you're taking the input as an <code>int</code> from the user, not to mention it was out of place and didn't have proper syntax.. What I am doing in the code above is continuing to loop until the input from the user is equal to <code>0</code> (an integer, not a string). If the user inputs <code>0</code>, then we simply break out of the loop and print the average. Until then, we continue to add the input to <code>addition_integer</code> and increment <code>division_integer</code> by 1.</p>

<p>All in all, you were pretty close to the solution, you just needed a few syntax changes and to be steered in the right direction as to how you can break out of an infinite loop.</p>

<p>Finally, here is a test using the numbers that you've provided in your question:</p>

<pre><code>Enter test score: 80
Enter test score: 70
Enter test score: 90
Enter test score: 88
Enter test score: 0
The average is 82%
</code></pre>

python if-statement while-loop syntax-error average