Fixing positional argument errors in python

Hi, everyone. I could really use whatever help I can get. I am currently trying to write a code that simulates a game of cheating hangman. It tries to evade the player from guessing the correct word by changing it based on their guesses. It requires three files:,, and dictionary.txt. = class and methods for the game simulation = calls the play method to execute the game
dictionary.txt = is read into the to create the list of words used

When I attempt to run, tells me

  • "play() missing 9 required positional arguments: ‘askForWordLength’, ‘askForNumberOfGuesses’, ‘remainingWords’, ‘words’, ‘wordStatus’, ‘printCountOfRemainingWords’, ‘printGameStats’, ‘askPlayerForGuess’, and ‘retrieveRemainingWords’ "

I am not sure how to fix this error. I have made sure the methods have the (self): parameter on their declaration, I have made sure that each calls the necessary functions after being defied, and even used a linter that does not detect this prior to execution. I am out of options
from hangman import Hangman

Create an instance of hangman

game = Hangman()

Call play method that begins and plays the game

Game is over. Ask if user would like to play again.

y = input("Would you like to play again? yes or no: ")

Continuously play and ask user to play again.

while y == ‘yes’:
y = input("Would you like to play again? yes or no: ")
import re

class Hangman:

# hangman self method

def hangman(self):

    self.hangman = Hangman()  # object of the Hangman class

def words(self):

    with open('dictionary.txt') as file:  # opens dictionary text file

        file_lines =  # reads and splits each line

    all_words = []  # empty list to contain all words

    valid_words = []  # empty list to contain all valid words

    for word in file_lines:  # traverses all words in the file lines

        if len(word) >= 3:  # accepts word if it has at least 3 letters

            all_words.append(word)  # appends accepted word to list

    # list of all invalid characters in python

    CHARACTERS = ["~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(",

                  ")", "-", "_", "=", "+", "[", "]", "{", "}", "|", "\","

                  "", "'", "?", "/", ">", ".", "<", ",", "", ";", ":"]

    for i in CHARACTERS:    # traverse list of invalids

        for word in all_words:

            if i not in word:   # if invalid character is not in word

                valid_words.append(word)    # accept and append to list

    return valid_words  # return list of valid words

def askForWordLength(self, valid_words):

    word_lengths = []   # empty list for possible word lengths

    for word in valid_words:    # traverse list of valid words

        length = word.__len__()  # record length of current word

        if (length not in word_lengths):

            word_lengths.append(length)     # accept and append to list


    # inform user of possible word lengths

    print('The available word lengths are: ' + str(word_lengths[0]) + '-'

          + str(word_lengths[-1]))


    # have user choose from possible word lengths



            length = int(input('Please enter the word length you want: '))

            if (length in word_lengths):

                return length

        except ValueError:

            print('Your input is invalid!. Please use a valid input!')


def askForNumberOfGuesses(self):



            num_guesses = int(input('Enter number of guesses you want: '))

            if (num_guesses >= 3):

                return num_guesses

        except ValueError:

            print('Your input is invalid!. Please use a valid input!')


def wordStatus(self, length):

    status = '-'

    for i in range(0, length):

        status += '-'


def remainingWords(self, file_lines, length):

    words = []

    for word in file_lines:

        if (word.__len__() == length):


    return words

def printGameStats(self, letters_guessed, status, num_guesses):

    print('Game Status: ' + str(status))


    print('Attempted Guesses' + str(letters_guessed))

    print('Remaining Guesses' + str(num_guesses))

def askPlayerForGuess(self, letters_guessed):

    letter = str(input('Guess a letter: ')).lower()

    pattern = re.compile("^[a-z]{1}$")

    invalid_guess = letter in letters_guessed or re.match(pattern, letter) == None

    if (invalid_guess):

        while (1):


            if (re.match(pattern, letter) == None):

                print('Invalid guess. Please enter a correct character!')

            if (letter in letters_guessed):

                print('\nYou already guessed that letter' + letter)

            letter = str(input('Please guess a letter: '))

            valid_guess = letter not in letters_guessed and re.match(pattern, letter) != None

            if (valid_guess):

                return letter

    return letter

def retrieveWordStatus(self, word_family, letters_already_guessed):

    status = ''

    for letter in word_family:

        if (letter in letters_already_guessed):

            status += letter


            status += '-'

    return status

def retrieveRemainingWords(self, guess, num_guesses, remaining_words,

                           wordStatus, guesses_num, word_length,




    word_families = createWordFamiliesDict(remaining_words, guess)

    family_return = wordStatus(word_length)

    avoid_guess = num_guesses == 0 and family_return in word_families

    if (avoid_guess):

        family_return = wordStatus(word_length)


        family_return = findHighestCountWordFamily(word_families)

    words = generateListOfWords(remaining_words, guess, family_return)

    return words

def createWordFamiliesDict(self, remainingWords, guess):

    wordFamilies = dict()

    for word in remainingWords:

        status = ''

        for letter in word:

            if (letter == guess):

                status += guess


                status += '-'

        if (status not in wordFamilies):

            wordFamilies[status] = 1


            wordFamilies[status] = wordFamilies[status] + 1

    return wordFamilies

def generateListOfWords(self, remainingWords, guess, familyToReturn):

    words = []

    for word in remainingWords:

        word_family = ''

        for letter in word:

            if (letter == guess):

                word_family += guess


                word_family += '-'

        if (word_family == familyToReturn):


    return words

def findHighestCountWordFamily(self, wordFamilies):

    familyToReturn = ''

    maxCount = 0

    for word_family in wordFamilies:

        if wordFamilies[word_family] > maxCount:

            maxCount = wordFamilies[word_family]

            familyToReturn = word_family

    return familyToReturn

def printCountOfRemainingWords(self, remainingWords):

    show_remain_words = str(input('Want to view the remaining words?: '))

    if (show_remain_words == 'yes'):

        print('Remaining words: ' + str(len(remainingWords)))



def play(self, askForWordLength, askForNumberOfGuesses, remainingWords,

         words, wordStatus, printCountOfRemainingWords, printGameStats,

         askPlayerForGuess, retrieveRemainingWords):

    MODE = 1

    openSession = 1

    while (openSession == 1):

        word_length = askForWordLength(words)

        num_guesses = askForNumberOfGuesses()

        wordStatus = wordStatus(word_length)

        letters_already_guessed = []


        game_over = 0

        while (game_over == 0):

            if (MODE == 1):


        printGameStats(remainingWords, letters_already_guessed,

                       num_guesses, wordStatus)

        guess = askPlayerForGuess(letters_already_guessed)


        num_guesses -= 1

        remainingWords = retrieveRemainingWords(guess, remainingWords,

                                                num_guesses, word_length)

        wordStatus = wordStatus(remainingWords[0], letters_already_guessed)


        if (guess in wordStatus):

            num_guesses += 1

        if ('-' not in wordStatus):

            game_over = 1

            print('Congratulations! You won!')

            print('Your word was: ' + wordStatus)

        if (num_guesses == 0 and game_over == 0):

            game_over = 1

            print('Haha! You Lose')

            print('Your word was: ' + remainingWords[0])

    print('Thanks for playing Hangman!')

Maybe each parameter of the play function (except for self) should have a default value (for starting the game at least).

Here’s an example of a function that has a default for the start parameter:

def count5(start = 0):
   return list(range(start, start + 5))

or like this:

def count5(start = None):
   if start is None:
      start = 0
   return list(range(start, start + 5))

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.