I am wondering why the following program does not print 'b'. It is is very simple code; I think it must work; and do not know the reason why it doesn't.
def a():
if b > 10:
print 'b'
sys.exit(1)
# main
while 1:
a()
b += 1
b is global variable. Actual code is more complicated but the structure is the same as mine. I guess when I call a() function and if b is greater than 10, it shows 'b'. However, it does not go inside if-statement.
Would you help me out how to solve?
Thanks.
if? Please clarify.globla bin front ofdef a():and it works fine with 'b' printed. It did go inside if-statement. (Python 2.7.2 Win32)NameError: global name 'b' is not defined. The solution is not theglobal b. It'sb = 0before the loop starts!