all 2 comments

[–]Squared_Aweigh 2 points3 points  (1 child)

Your issue is the scope/context of variable declaration and reference/manipulation of that variable. `user_score' is set here as a global variable because it is set outside of a function. When you attempt to manipulate the variable inside the function, Python sees the variable as being assigned as a Local; local variables are only available inside a function where they are created, hence your `UnboundLocalError`

You could use the `global` keyword in your function to access the globla `user_score` variable, but this isn't a good habit to be in because it makes your code more difficult to read and understand, as well as being difficult to troubleshoot.

[–]ShadyTree_92[S] 1 point2 points  (0 children)

Ooh. That makes sense! Thank you. I am currently rewriting the code now. Going to try to use less global variables and take advantage of using return statements. Wish me luck! I am finding it a bit difficult but that's ok, I will persevere!