Hi I have a question regarding the code below. I define the variable money before I define the function, nevertheless, when I don’t define money INSIDE the function, I get an error that money is referenced before assignment.
On the other hand I define num also before the function and not inside the function. This does not cause the above mentioned error. Do you have any idea why? I think this is because I do not do arithmetics on this num variable. But I still don’t understand why this is the reason for the error.
import random money = 100 num = random.randint(0,10) print(num) heads = num<= 5 tails = num>5 def coin_flipping(guess, amount): money = 100 if guess == True: money += amount else: money -= amount print(money) if num <= 5: print('heads') else: print('tails') coin_flipping(heads,50)