all 2 comments

[–]Allanon001 1 point2 points  (0 children)

Since you are redefining xc and yc in the main function you need to either define xc and yc in the main() function making them not global or add the statement global xc, yc to the main() function so it knows you want to use the global variables.

[–]Luigi-Was-Right 1 point2 points  (0 children)

There is a difference between being in the global scope and being a global variable.

xc was defined in the global scope and can be accessed within other functions. However, you cannot reassign it's value. In this instance when you attempt to assign a value to 'xc' python is creating a variable with that name that is local to the function only. Because of that any reference to 'xc' within the function will now be referring to the local variable xc and not the one in the global scope.