I keep receiving the following error when running the code
UnboundLocalError: local variable 'winner' referenced before assignment
The following is my code
# Create a Number Guessing Game
humannum = int(input("Enter a number from 1 - 10> "))
computernum = random.randint(1,10)
Winner = False
def winner(): # How to allow the user to try again
while Winner != True:
print("Your answer was not correct, please try again")
print(humannum)
def calculator(): # This is to calculate, who wins the game
if humannum == computernum:
print(f'The computer number was {computernum}')
print(f'Your number was {humannum}')
print("")
print("Therefore You have won ! ")
winner = True
elif humannum <= computernum:
print("Your number was larger than the computer")
winner()
elif humannum >= computernum:
print("Your number was larger than the computers")
winner()
calculator()
I am not sure why this is happening when I believe I have my variable winner referenced above me calling it which is below in the calculator function.