Python – TypeError: inputNames() takes no arguments (2 given)

argumentspython

#Lab 7-3 The Dice Game
#add libraries needed
import random

#the main function
def main():
    print

    #initiliaze variables
    endProgram = 'no'
    playerOne = 'NO NAME'
    playerTwo = 'NO NAME'

    #call to inputNames
    playerOne, playerTwo = inputNames(playerOne, playerTwo)

    #while loop to run program again
    while endProgram == 'no':
        winnersName = 'NO NAME'
        p1number = 0
        p2number = 0

        #initiliaze variables

        #call to rollDice
        winnerName = rollDice(playerOne, playerTwo, winnerName)

        #call to displayInfo
        winnerName = displayInfo (winnerName)

        endProgram = input('Do you want to end program?(Enter yes or no): ')

#this function gets players names
def inputNames():
    inputNames = string('Enter your names: ')
    return playerOne, playerTwo    

#this function will get the random values
def rollDice():
    p1number = random.randint(1,6)
    p2number = random.randint(1,6)
    if p1number >= p2number:
        winnerName = playerOne
    if p1number == p2numer:
        winnerName = 'TIE'
    elif winnerName == playerTwo:
        return winnerName

#this function displays the winner
def displayInfo():
    print ('The winner is: ', winnerName)


#calls main
main()

Beginner programmer here and trying to complete an assignment. Line 19 returns the error : TypeError: inputNames() takes no arguments (2 given). Line 19: playerOne, playerTwo = inputNames(playerOne, playerTwo). This line is provided by my professor and I cannot figure out how to make it work. Any help would be greatly appreciated!

Best Solution

the function inputNames is defined as a function taking no arguments, but you are passing it two variables in the method list:

here is how you defined it:

def inputNames():
    inputNames = string('Enter your names: ')
    return playerOne, playerTwo  

here is how you called it:

playerOne, playerTwo = inputNames(playerOne, playerTwo)

what you really want is this function to return the names of player one and player two. so the line above should really be:

playerOne, playerTwo = inputNames()

and the function will have to gather the two names locally and return those, maybe something like this:

def inputNames():
    p1 = str(raw_input("Enter the name for player one: "))
    p2 = str(raw_input("Enter the name for player two: "))
    return p1, p2