Jan-07-2018, 08:08 AM
(This post was last modified: Jan-07-2018, 08:08 AM by Gribouillis.)
When a variable such as
A way to solve this is to add the statement
It is good practice to avoid global statements in python code, because they obfuscate the code somewhat, but they are allowed.
answers_right
is on the left hand side of an assignment operator in a function, it becomes a local variable of this function. It means that the answers_right
variable in function finder()
is not the same as the global variable answers_right
. Python complains because you are incrementing the local variable when this variable doesn't yet have a value.A way to solve this is to add the statement
global answers_right
at the top of the finder()
's function body.It is good practice to avoid global statements in python code, because they obfuscate the code somewhat, but they are allowed.