0
I want to increment the global variable when i call a function but its giving me an error can some body help me out
x=0 def main(): print(x) x+=1 def check(): for I in range(10): main() check() expected output: 0 1 2 3 4 5 6 7 8 9 10 actual outpu: UnboundError: Local variable referenced before assignment
3 Answers
+ 6
add 'global x' after 'def main():'
+ 4
you have to use global specifier for use global vars inside functions
0
thank you very much it's worked