So basically i defined the variable before (globally)
However, it still says variable referenced before assignment.
I am a beginner and i dont know how to use this so please forgive me if i am doing something wrong
import time
import multiprocessing
i = True
upgrade_level = 0
money = 10
def clear_chat():
num = 0
while num < 100:
print(" ")
num += 1
def loop1():
while i:
question = input("Would you like to upgrade? (y)\n")
if(question.lower() == "y"):
if(money >= 10):
clear_chat()
money = money-10
print("You upgraded once")
print("Your upgrade level is " + str(upgrade_level))
elif(money < 10):
clear_chat()
print("You do not have enough money ($10) to buy an upgrade")
else:
clear_chat()
print("You can only input (y)")
def loop2():
while i:
money += 10
time.wait(10)
p1 = multiprocessing.Process(target = loop1())
p2 = multiprocessing.Process(target = loop2())
>Solution :
First time.wait() is accully time.sleep().
The main problem in your code is, you haven’t added the global keyword in function. you can read the global variable without global keyword, but in order to make changes in it you have to use global keyword, i.e use global money in both loops.