This is the code that I am working on right now:
def getWinner(userChoice, computerChoice):
if userChoice == "rock" and computerChoice == "scissors":
winner = userChoice
elif userChoice == "paper" and computerChoice == "rock":
winner = userChoice
elif userChoice == "scissors" and computerChoice == "paper":
winner = userChoice
elif userChoice == "rock" and computerChoice == "paper":
winner = computerChoice
elif userChoice == "paper" and computerChoice == "scissors":
winner = computerChoice
elif userChoice == "scissors" and computerChoice == "rock":
winner = computerchoice
elif userChoice == computerChoice:
winner = "It's a tie."
return(winner)
userChoice = input("Enter your choice:")
computerChoice = print(getComputerChoice())
winnerOfGame = getWinner(userChoice, computerChoice)
print(winnerOfGame)
I am trying to set up a rock, paper, scissors game, but every time I try to run this function, it returns with:
Traceback (most recent call last):
File "C:/Python34/idk 2.py", line 45, in <module>
winnerOfGame = getWinner(userChoice, computerChoice)
File "C:/Python34/idk 2.py", line 41, in getWinner
return(winner)
UnboundLocalError: local variable 'winner' referenced before assignment
I have tried assigning a global variable, but nothing seems to be working when I try to fix it. When I do other if statements like this, I do not have issues with the variable being referenced before assignment, and I am doing nothing differently.