This is my code, sorry it is in Swedish but it is basically rock, paper, scissors.
I get the error UnboundLocalError: local variable 'Answer' referenced before assignment
even though if the input is correct, the variable should be assigned.
The input has to be either rock, paper or scissors and if it's not it starts over. But even when the input is correct it says "Answer" is not assigned. Please help, have been stuck on this problem for a while. And no making it global
is not an option since it has to be random each round.
def Start():
global win
global lost
game = input("Skriv sten, sax eller påse: ")
game2 = game.lower()
notright = game2 is "sten" or "sax" or "påse"
if game2 == "quit":
quit
if notright == True:
Answer = random.randint(0,3)
if Answer == 1:
print ("Du valde",game2,"och Jag valde Sten")
elif Answer == 2:
print("Du valde",game2,"och Jag valde Sax")
elif Answer == 3:
print("Du valde",game2,"och Jag valde Påse")
elif notright == False:
print("Du måste välja sten, sax eller påse. Prova igen!")
Start()
if Answer == 1 and game2 == "sten":
print("Det blir oavgjort")
elif Answer == 1 and game2 == "sax":
lost = True
elif Answer == 1 and game2 == "påse":
win = True
elif Answer == 2 and game2 == "sten":
win = True
elif Answer == 2 and game2 == "sax":
print("Det blir oavgjort")
elif Answer == 2 and game2 == "påse":
lost = True
elif Answer == 3 and game2 == "sten":
lost = True
elif Answer == 3 and game2 == "sax":
win = True
elif Answer == 3 and game2 == "påse":
print("Det blir Oavgjort")