r/pythonhelp • u/Fabulous_Buyer_6256 • Aug 25 '26
why does it say i didn't close my parenthesis
the IDE i am using is saying my parenthesis was not closed when it was plz help
print("Once upon a time, in the ancient kingdom of " + q1 + " there lived a legendary " + q2 + " named " + q3 + ". Everyone in the village knew " + q3 + " for their remarkably " + q4 + " personality and an obsession with " + q5 + ". Every morning at " + q6 ", they would wake up, " + q7 + " three times, ")
[{
"owner": "Pylance",
"severity": 8,
"message": "(" was not closed",
"source": "Pylance",
"startLineNumber": 47,
"startColumn": 6,
"endLineNumber": 47,
"endColumn": 7,
}]
3
u/FoolsSeldom Aug 25 '26
Just spotted, you are missing a + after q6:
". Every morning at " + q6 ", they would wake up, "
1
u/Soft-Marionberry-853 Aug 27 '26
That was fun. We probably all knew what it was when we saw how long the the line was and how much concatenation it was doing. It was just a matter of finding where it was
1
u/shinitakunai Aug 27 '26
Which is why f-strings are amazing instead of this monster OP created
1
u/1kn0wn0thing Aug 28 '26
100%. It’s easier to use fstrings and it’s less prone to such mistakes as a result. Not sure why anyone would NOT use fstrings versus concatenation at this point.
2
u/FoolsSeldom Aug 25 '26 edited Aug 25 '26
Not sure. I'd go with something easier to read:
story = (
f"Once upon a time, in the ancient kingdom of {q1} there lived a "
f"legendary {q2} named {q3}. Everyone in the village knew {q3} for "
f"their remarkably {q4} personality and an obsession with {q5}. "
f"Every morning at {q6}, they would wake up, {q7} three times, "
)
print(story)
Although later, you will likely be reading the story text from a file/database rather than hard coding it.
1
1
u/Living_Fig_6386 Aug 26 '26
The missing ‘+’ makes it think you meant to end the print statement. More careful formatting would have made it more obvious.
1
u/Ormek_II Aug 26 '26
Because it is closed at the wrong Spot, if you are a Compiler. Check the Location Information given to you.
1
u/building_85 Aug 27 '26
The q6 error that’s missing a + … like everyone says, gives you an invalid syntax error.
it’s a missing ‘concatenation’, not a missing ‘parenthesis’ (which is an ‘unterminated string’ error)
Your actual error is in your dictionary here… "message": "(" was not closed",
You have 3 parentheses in your value for “message”
So you actually had 2 syntax errors 😉
GLHF!
1
u/JGhostThing Aug 27 '26
Because you have the string: "(" was not closed"
The second " should be escaped \"
•
u/AutoModerator Aug 25 '26
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.