Simple python question.
This seems kind of silly, but I must be missing something, as I cannot for the life of me get this counting button to work.
It should work like this:
1. Varible A is definied as 0
2.The command 'count' is then executed when the button is pressed. Count Adds 1 to A, A is then printed, repeat step 2 for each button press.
It seems so silly that I cant get this to work, it says A is yet to be defined, despite that being the third thing I do. Help would be appreciated, as I'm playing to do a calculator with this as more or less the base.
I don't know why the pastebin code doesn't work, but this does:
a = 0
global a # I just added this line.
a += 1
Thats because if you want the varible to be in existence throughout the whole project you need to declare it as global. If not python will just overwrite it each time it sees that varible. Good practice is to put the "global a" at the very top of the project.
Originally Posted by Samhain13