This question already has answers here: UnboundLocalError trying to use a variable (supposed to be global) that is (re)assigned (even after first use) (14 answers) Closed 5 months ago. I keep getting a syntax error when using += in python here is my code. I am also having troule with nonlocal. I am getting lots of errors including syntax errors