Python Hangman Game finishing touches
Question: Here is my code:

    
    
    def randWord():
    """opens a file of words and chooses a random word from the file"""
        infile = open('dictionary.txt','r')
        wordList = infile.read()
        wordList2 = wordList.split('\n')
        infile.close()
        randWord = str(random.choice(wordList2))
        return randWord
    
    def hangman():
    """initiates the game by explaining the rules and terminates when game is over"""
        global roundsWon
        global roundsPlayed
        print('\nWelcome to hangman! The rules are simple: A word will be chosen at random and will be represented by a sequence of blanks. Each blank constitutes a letter in the word. You will be asked to enter a letter and if the letter is contained in the word you will be notified. You can only make an incorrect guess 8 times before you lose the round. To win the round you must guess all the letters and reveal the word. Good luck!\n\n')
        word = randWord()
        while True:
            guess = letterGuess(word)
            if checkGuess(guess,word):
                roundsWon += 1
                roundsPlayed +=1
                print('\nYou won! The word is {}.'.format(word))
                break
            elif guessesLeft == 0:
                print("\nI'm sorry, but you have run out of guesses. The word was {}.".format(word))
                roundsPlayed +=1
                break
    
    def letterGuess(word):
    """asks the user to guess a letter and prints the number of guesses left"""
        blankedWord(word)
        guess = input('\nGuess a letter: ')
        return guess
    
    def blankedWord(word):
    """converts the random word into the proper blanked form based on the letter guessed and lets the user know if their letter is in the word"""
        displayWord=''
        for letter in word:
            if guessedLetters.find(letter) > -1: 
                displayWord = displayWord + letter         #checks if the letter guessed is contained in the random word string by index.
                print('\n{} is contained in the word!'.format(letter))
            else:
                displayWord = displayWord + '-'
        print(displayWord)
    
    def checkGuess(guess,word):
    """checks if the user enters a single letter guess or the full word"""
        if len(guess) > 1 and len(guess) == len(word):
            return completeWordGuess(guess,word)
        else:
            return oneLetterGuess(guess, word)
    
    def completeWordGuess(guess,word):
    """analyzes the complete word guess to check if is correct"""
        global guessesLeft
        if guess.lower() == word.lower(): #kept it lower case for simplicity
            return True
        else:
            guessesLeft -=1
            return False
    
    def oneLetterGuess(guess,word):
    """checks to see if the single letter guess is included in the whole word"""
        global guessedLetters
        global guessesLeft
        global guessesMade
        if word.find(guess) == -1: #checks for failure on .find function
            guessesLeft -= 1
            guessesMade += 1
            print('\nThat letter is not in the word. You have made {} incorrect guesses and have {} guesses left.'.format(guessesMade,guessesLeft))
    
        guessedLetters = guessedLetters + guess.lower()
        if allGuessedLetters(word):
            return True
        return False
    
    def allGuessedLetters(word):
    """checks if all of the letters in the word have been uncovered/guessed"""
        for letter in word:
            if guessedLetters.find(letter) == -1: #checks for failure on .find function
                return False
            return True
    
    def gameStats():
    """prints the final statistics of a play session"""
        print('\nYou have played {} games and you have won {}     rounds!'.format(roundsPlayed,roundsWon))
    
    import random
    guessesMade = 0
    guessesLeft = 8
    roundsPlayed = 0
    roundsWon = 0
    guessedLetters = ''
    userMode = 1
    
    while userMode==1:
        if userMode == 1:
            hangman()
            guessesLeft = 8
            guessedLetters = ''
            userMode = eval(input('\nEnter 1 to play again, type 0 to end the game: '))
        else:
            break
    gameStats()
    

The program seemingly runs well except for one part: If the user guesses the
first letter of the word the program treats it as the complete right word and
counts it as a win. So if I the word was 'rhino' and I guessed an 'r' it would
show as a win. I don't see the mistake, however I have a feeling it is in the
function completeWordGuess and I am not sure if I should be returning True for
the first conditional. Any help is appreciated.


Answer: I think the main problem - and I say I think because I haven't had a chance to
tear your code apart looking for other ways it's not working, and I probably
won't - is that you've put your return False call in allGuessedLetters in the
wrong place. This is what you had:

    
    
    def allGuessedLetters(word):
    """checks if all of the letters in the word have been uncovered/guessed"""
    for letter in word:
        if guessedLetters.find(letter) == -1: #checks for failure on .find function
            return False
        return True
    

The problem is that, if the first letter does not return False, the control
flow moves to return True, given that "return True" is a part of every
iteration of the for loop. The only way that method doesn't return True is if
the first letter hasn't been guessed yet.

If you alter it like so:

    
    
    def allGuessedLetters(word):
        """checks if all of the letters in the word have been uncovered/guessed"""
        for letter in word:
            if guessedLetters.find(letter) == -1: #checks for failure on .find function
                return False
        return True
    

the method works as intended, because the control flow only moves to return
True once the entirety of the for loop has been encountered and every letter
has been evaluated, resulting in a termination if any of them don't match.

