How can I solve the positional arguments error?

I am trying to write a simple code for the “rock, paper, scissors” game (I’m new to Python, so still struggling with functions).

The key error is currently with positional arguments and calling defined functions in other functions (e.g. PickWinner function is missing positional arguments, i.e. cpuChoice, playerChoice).

How can I correctly call the different functions?

import random 
goal = 30
Count_computer = 0
Count_player = 0
Words = ["Rock","Paper","Scissors"]

def update():
  if Count_computer < goal and Count_player < goal:
    print ("Computer has", Count_computer, "You have", Count_player)
    print ("Welcome to a game round")
  elif Count_computer >= goal:
      print ("Oh nooo! Computer wins...")
  elif Count_player >= goal:
      print ("Yes, great game! You win!")

def getPlayerChoice(userChoice):
  userChoice = input("Please enter your choice: ")
  if userChoice == "Rock":
    print ("You chose Rock")
  elif userChoice == "Paper":
    print ("You chose Paper")
  elif userChoice == "Scissors":
    print ("You chose Scissors")
  else:
    print ("You cannot choose this, only Rock, Paper and Scissors are allowed")

def getComputerChoice(cpuChoice):
  cpuChoice = random.choice(Words)
  print ("Computer chose",cpuChoice)

def PickWinner():
  if cpuChoice == userChoice:
    print ("Computer has", Count_computer, "points;", "Player has", Count_player, "points")
  elif cpuChoice == "Rock" and userChoice == "Paper":
    Count_player+=1
    print ("Computer has", Count_computer, "points;", "Player has", Count_player, "points")
  elif cpuChoice == "Paper" and userChoice == "Scissors":
    Count_player+=1
    print ("Computer has", Count_computer, "points;", "Player has", Count_player, "points")
  elif cpuChoice == "Scissors" and userChoice == "Rock":
    Count_player+=1
    print ("Computer has", Count_computer, "points;", "Player has", Count_player, "points")
  else:
    Count_computer+=1
    print ("Computer has", Count_computer, "points;", "Player has", Count_player, "points")

def main():
  print("Welcome to the rock-paper-scissors game")
  print("This game ends when one player reaches", goal, "points")
  print("You can enter only Rock, Paper, Scissors ...spelled exactly this way")
  update()
  getPlayerChoice()
  getComputerChoice()
  PickWinner()

if __name__ == "__main__": main()

Hello, @system9414517039, and welcome to the Codecademy Forums!

You have a couple of function definition headers, such as this one:

def getPlayerChoice(userChoice):

However, your next line assigns a value to userChoice, which is the function parameter. That parameter in the header is not needed.

The error, as far as the Python interpreter is concerned, is that you call the function later without passing it any arguments to correspond to the parameters. Your function calls can be left as they are. Remove the unnecessary parameters from the headers of the function definitions.

1 Like

Hi @appylpye, thanks for the help!

I’ve removed the headers, however I still receive an error:
“PickWinner() missing 1 required positional argument: 'userChoice”

Hello @system9414517039!! :grinning:

If they want you to have a parameter than you could assign userChoice before calling the function

name = input('Please enter your name: ')

def greetings(name):
    print('Welcome to the game ' + name + '!')

Just don’t assign the variable inside the function, as @appylpye has said.

2 Likes

thank you very much to both of you! Just solved the issue as you specified.

2 Likes

Your welcome!! Happy coding :grinning:

1 Like