-1

Yo, I was tryna make something and lets say this is my code:

import threading
uwu = 0
def main():
    def e():
        if uwu > 10:
            print("no u")
            uwu += 1
        elif uwu <= 10:
            print('Hello, World!')
            uwu += 1
    done = False
    while not done:
        try:
            if threading.active_count() < 100:
                threading.Thread(target=e).start()
        except IndexError:
            done = True
            print("Done!")
            input()

main()

So, when I execute it I get this error:

 File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "ask stacc xd.py", line 5, in e
    if uwu > 10:
UnboundLocalError: local variable 'uwu' referenced before assignment

If anyone could help me out with this please answer or comment.

Mysterious K
  • 79
  • 2
  • 8

1 Answers1

2

You are referring global variable. try with global keyword.

import threading
uwu = 0
def main():
    def e():
        global uwu
        if uwu > 10:
            print("no u")
            uwu += 1
        elif uwu <= 10:
            print('Hello, World!')
            uwu += 1
    done = False
    while not done:
        try:
            if threading.active_count() < 100:
                threading.Thread(target=e).start()
        except IndexError:
            done = True
            print("Done!")
            input()

main()
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61