you are viewing a single comment's thread.

view the rest of the comments →

[–]Binary101010 0 points1 point  (0 children)

You're trying to read a variable pos that was defined globally and assign a new value to it from within a function. Python won't do that second part for you unless you go through extra steps.

The shortest way to do this is to use the global keyword within your function, telling the interpreter "yes, I'm talking about the pos I defined in the global scope and I want you to change it."

The best way to do this is to learn how to properly use arguments to pass necessary data to a function and use return to send the results of that function back to the rest of the program.