Reputation: 3
I'm working on a small project and I've run into a SyntaxError. As far as I know, the syntax is correct but I'm not sure.
Here's the code I used:
print(yellow + "You " + green + "won" + yellow + " a total of " + cyan + str(correct_guess) + yellow + " game(s), and " + red + "lost" + yellow + " total of " + cyan + str(incorrect_guess) + yellow + " game(s).")
All of the variables used are defined in the code preceding this line (the variables named after colors being ANSI escape sequences that all work in other print lines). Here's another line of code that doesn't throw an error, but has the exact same syntax:
print(yelow + "Throughout all of the games played, you guessed a total of " + cyan + str(total_guess) + yellow + " times.")
This one works for some reason, while the one above does not.
When I ran the code it threw a SyntaxError. The code looks like it doesn't have one, though. I'm not sure how to fix it. The code above defines all of the variables used, and I used proper indentation. It's also telling me that the error comes after the final parenthesis.
Upvotes: 0
Views: 272
Reputation: 615
Between "You "
and green
a +
* is missing.
To investigate this sort of problems, you can first split the long command in little pieces and then collect them.
print(yellow)
work? yes -> the problem is not hereprint(yellow + "You ")
work? yes -> the problem is not hereprint(yellow + "You " green)
work? no -> the problem is here!Upvotes: 1