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

7th Oct 2018, 4:45 PM
Velivela Sai Chinna Madhu Babu
Velivela Sai Chinna Madhu Babu - avatar
1 Antwort
+ 3
Add "global x" at the beginning of the function main()
7th Oct 2018, 5:16 PM
Anna
Anna - avatar