My Rock Paper Scissors code doesn't work and I'm assuming it's because I'm using the return value incorrectly. What should I do?
EDIT, so I've stored the return like this
def results (x, y):
if (x == "R" or x == "rock" or x == "r" or x == "Rock" or x == "ROCK") and (y == "S" or y == "s" or y == "Scissors" or y == "SCISSORS" or y == "scissors"):
winner = 1
return winner
But how do I get "winner" to print outside of the function?
OLD
player1 = input ("Player 1: Please enter either Rock, Paper or Scissors:")
player2 = input ("Player 2: Please enter either Rock, Paper or Scissors:")
def results (x, y):
if (x == "R" or x == "rock" or x == "r" or x == "Rock" or x == "ROCK") and (y == "S" or y == "s" or y == "Scissors" or y == "SCISSORS" or y == "scissors"):
return 1
else:
if (x == "rock" or x == "r" or x =="R" or x == "Rock" or x == "ROCK") and (y == "P" or y == "p" or y == "paper" or y == "Paper" or y == "PAPER"):
return 2
else:
if (x == "rock" or x =="R" or x == "r" or x == "Rock" or x == "ROCK") and (y == "rock" or y =="R" or y == "r" or y =="Rock" or y == "ROCK"):
return 0
else:
print ("Sorry, I didn't understand your input")
results (player1, player2)
if results == 1:
print ("Player 1 wins!")
else:
if results == 2:
print("Player 2 wins!")
else:
if results == 0:
print("It was a tie!")
rock_list = ["rock","R","r"]andif x in rock_list:this looks better but it's only style thing so still your choice to use it or not.