# Rock-Paper-Scissors-Pencil-Fire game with functions doesn't work

I am trying to make a game of rock-paper-scissors-pencil-fire with functions and it doesn't work. It seems that it can't go inside the compare function(named findwinner()) and return the results.

i looked throw the web for help but i couldn't find anything. i tried assigning the variables in many different ways but with no luck.

python

``````#Rock-Paper-Scissors-Fire-Pencil Game
#Game:
#The player must choose his weapon and 'fight' against the computer following #the rules above.
#The player can choose between the following: Rock, Scissors, Fire, Pencil and #Paper.
#Rules: The rock beats the scissors, the scissors beat the fire, the fire #beats the pencil, the pencil beats the paper and the paper beats the rock

#Player1 is the human player
#Player2 is the computer
import random
#The game welcomes the player.
print("Wellcome to the Rock-Paper-Scissors-Fire-Pencil game!")
#The player can play as many times as he/she wants until he/she type anything #else except yes in the "Do you want to play again?" question.
def getuser():
choices = ["rock", "scissors", "fire", "pencil", "paper"]
#The computer chooses it's 'weapon'.
player2 = choices[random.randint(0,4)]
player1 = None
while player1 not in choices:
#The player must choose his/her 'weapon'
player1 = input("\n PLAYER 1 - Please make a choice (rock/paper/scissors/fire/pencil):")
print (f"\nPlayer1 choose {player1}")
print (f"\nPlayer2 choose {player2}")
return ()

def findwinner():
winner = None
p1 = getuser()[1]
p2 = getuser()[2]
#The game keeps how many times the player1 has won, lost or tied with the computer in the variables bellow.
wins = 0
losses = 0
ties = 0
#The game compares the choises of the players and announces if the human player won, lost or tied with the computer.
#Then it adds the win, the lost or the tie to the summary of wins, losses or ties.
if p1 != p2:
if p1 == "rock":
if p2 == "scissors" or p2 == "pencil" or p2 == "fire":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "paper":
if p2 == "rock":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "scissors":
if p2 == "paper" or p2 == "pencil":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else :
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "pencil":
if p2 == "paper":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "fire":
if p2 == "paper" or p2 == "scissors" or p2 == "pencil":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
else:
print("\n The round is a tie!")
winner = None
ties += 1
print (f"\nThe winner of this round is {winner}")

return (winner, wins, losses, ties)

play_again = "yes"

while play_again == "yes":

#The game shows the choises of the players.
player1 = getuser()[1]
player2 = getuser()[2]
findwinner(player1, player2)

#The game askes the player if he/she wants to play again.
play_again = input("\nDo you want to play again?:")
else:
#If the player doesn't want to play again, the game prints the results of all the rounds of the game and closes.
print(f"The player1 won {findwinner()[2]} times")
print(f"The player1 lost {findwinner()[3]} times")
print(f"The player1 tied {findwinner()[4]} times")
print("\n Good Bye")
``````

On Best Solutions

You got a couple of problems:

1. getuser() just prints the choices but does not return them, to fix this just change the return to player1, player2

2. findwinner() does not get any parameters according to the signature, you have to change the signature to findwinner(p1, p2)

3. If you are receiving the players choices by argument in findwinner(), you don't have to call getuser() again.

4. Wins, losses and ties counters are going to be reset each time you call findwinner() you have to declare them as globals outside the function, and then update them inside the function.

After fixing these, you end up with this:

``````import random
#The game keeps how many times the player1 has won, lost or tied with the computer in the variables bellow.
# 4 FIX) declare counters as globals
wins = 0
losses = 0
ties = 0
#The game welcomes the player.
print("Welcome to the Rock-Paper-Scissors-Fire-Pencil game!")
#The player can play as many times as he/she wants until he/she type anything
#else except yes in the "Do you want to play again?" question.
def getuser():
choices = ["rock", "scissors", "fire", "pencil", "paper"]
#The computer chooses it's 'weapon'.
player2 = choices[random.randint(0,4)]
player1 = None
while player1 not in choices:
#The player must choose his/her 'weapon'
player1 = input("\n PLAYER 1 - Please make a choice (rock/paper/scissors/fire/pencil):")
print (f"\nPlayer1 choose {player1}")
print (f"\nPlayer2 choose {player2}")
return player1, player2  # 1 FIX) return players choice

# 2 FIX) add players choice as parameters
def findwinner(p1, p2):
winner = None
# 3 FIX) do not call getuser since you have the player choices as arguments
# 4 FIX) use them as globals in the function scope
global wins, losses, ties
#The game compares the choises of the players and announces if the human player won, lost or tied with the computer.
#Then it adds the win, the lost or the tie to the summary of wins, losses or ties.
if p1 != p2:
if p1 == "rock":
if p2 == "scissors" or p2 == "pencil" or p2 == "fire":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "paper":
if p2 == "rock":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "scissors":
if p2 == "paper" or p2 == "pencil":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else :
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "pencil":
if p2 == "paper":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
if p1 == "fire":
if p2 == "paper" or p2 == "scissors" or p2 == "pencil":
print("\n Player1 wins this round!")
winner = p1
wins += 1
else:
print("\n Player2 wins this round!")
winner = p2
losses += 1
else:
print("\n The round is a tie!")
winner = None
ties += 1
print (f"\nThe winner of this round is {winner}")

return winner  # 4 FIX) no need to return the counters anymore

play_again = "yes"

while play_again == "yes":

#The game shows the choises of the players.
player1, player2 = getuser()  # 1 FIX) save player choices
findwinner(player1, player2)

#The game askes the player if he/she wants to play again.
play_again = input("\nDo you want to play again?:")
else:
#If the player doesn't want to play again, the game prints the results of all the rounds of the game and closes.
# 4 FIX) Use the global variables
print(f"The player1 won {wins} times")
print(f"The player1 lost {losses} times")
print(f"The player1 tied {ties} times")
print("\n Good Bye")
``````

I can tell you have problems understanding function returns. Each time you do findwinner() you are calling the function AGAIN, to run it only once and save the result you assign it to a variable. As done for getuser():

``````player1, player2 = getuser()
``````