Desperately need help

Can someone please look at this code and tell me what the syntax error is. I have looked at it 100 times and can’t find it. Even chat gpt can’t find it.

score_1 = float(input("Enter the first test score: ")) # First test score as a float.

score_2 = float(input("Enter the second test score: ")) # Second test score as a float.

score_3 = float(input("Enter the third test score: ")) # Third test score as a float.

number_of_scores = 3 # Constant representing the number of test scores.

total = score_1 + score_2 + score_3 # Total of all test scores.

average = total / number_of_scores # Average of the test scores.

print(f’Average test score: {average:.2%}') # Outputs the average with a % symbol.

It looks like the open quote in the last line print(f’Average is some kind of smart quote, not a plain single-quote/apostrophe character.

Thank you. I actually have no idea what that means. I typed the exact same symbol as at the beginning of the (f’average command) Can you tell me how to fix it?

Character is U+2019. It should be ', U+0027.

Your code has not been properly formatted for posting, which can cause quotes and other details not to display properly. Here it is copied from the page in raw format, and it does execute:

score_1 = float(input("Enter the first test score: "))  # First test score as a float.
score_2 = float(input("Enter the second test score: "))  # Second test score as a float.
score_3 = float(input("Enter the third test score: ")) # Third test score as a float.
number_of_scores = 3  # Constant representing the number of test scores.
total = score_1 + score_2 + score_3  # Total of all test scores.
average = total / number_of_scores # Average of the test scores.
print(f'Average test score: {average:.2%}')  # Outputs the average with a % symbol.

Also note that to display the result properly, with the decimal point in the correct place, the final line needs to be changed to the following:

print(f'Average test score: {average:0.2f}%')

Thank you.

1 Like

We’re glad to help.

Please remember that for various reasons, automated assistants such at ChatGPT can make mistakes. Be careful not to become overly dependent on them, because that could impede your learning of Python.

It is important to practice understanding error messages that are issued by the Python interpreter. The document 8. Errors and Exceptions provides some helpful information about that. Notice that it points out that when there is a SyntaxError, the message identifies a line number where it was discovered. When that happens, check that line and the previous one. Sometimes a SyntaxError relates to something that was done by mistake on the line prior to the one on which the Python interpreter discovered that there was a problem.

Some of us here initially had trouble finding the problem that you reported, because your code was not formatted properly for posting. The page About the Python Help category explains how to format posted code with the use of Markdown backticks.

After your code was properly formatted, the only obvious problem was not actually a SyntaxError. Rather it was a mistake in the formatting of the output.

We wish you the best of success in learning Python!

2 Likes