How to deal with the error 'invalid syntax'?

here is the error output:
File “/users/cDesktop/simp.py”, line 71
print(“sig”, str(nsig.getVal()), “bkg”, str(nbkg.getVal()))
^
SyntaxError: invalid syntax

Thanks in advance

Hello @wolfram420,
this is more a generic python question rather than a ROOT related one, it’s a bit out of scope of this forum :slight_smile:

However, the invalid syntax error may be raised in many situations, I list a few

  • Missing quotes. For example, print(Hello) instead of print("Hello").
  • Misspelled reserved keywords. For example, writing iff instead of if.
  • Incorrect Indentation. For example, missing required spaces or tabs.
  • Invalid function definitions or calls. For example, missing a colon in a function definition or missing parentheses in a function call.
  • Invalid variable declarations. For example, starting the variable name with a number or using invalid characters.
  • Missing operators. For example, missing the + operator when trying to add two numbers.

Good luck,
Monica

It looks like the quotation marks around the strings "sig" and "bkg" appear to be curly quotes (“ ”) instead of standard straight quotes (" "). Python and C++ require standard quotes for strings.

Thanks for you reply. I realize that I missed a right parenthesis above.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.