I'm quite new to Python and have been experimenting. So far I have made a simple hangman type game which creates a random word and the user then guesses it. I'd like to know if I've committed any bad practices so I can learn early on what to and not-to do.#Word Game Pythonfrom random import randint#Define an alphabet of valid lettersalphabet_file = alphabet.txt#Assign that to a listalphabet = open(alphabet_file).read().splitlines()#Define a word#Find the dictionaryword_file = words.txt#Assign the dictionary to a listwords = open(word_file).read().splitlines()#Define word based off a random word in the dictionaryword = words[randint(0,len(words))]#Make the word lower caseword = word.lower()#Make a list of guessesguesses = []#Make a list of correct guessescorrectGuesses = []#Make a list of incorrect guessesincorrectGuesses = []#Set a maximum number of incorrect guessesincorrectGuessesMax = 7#A function to help check if something is a numberdef isNumber (n):    try:        float(n)        return True    except ValueError:        return False#Returns True if a letter is in a worddef isInWord (letter,word):    #Make sure letter and word are both strings    if not letter in alphabet:        return False    #Make the letter lower case    letter = letter.lower()    #check if the letter is in the word    if letter in word:        #if so return true        return True    else:        #Otherwise return false        return False#Returns how many times a letter appears in a worddef timesInWord (letter,word):    #Make the letter Lower Case    letter = letter.lower()    #Define a variable to store the times letter is found    letterCount = 0    #Check if the letter is in the word    if isInWord(letter,word):        #Loop through word to find letter        for l in range(0,len(word)):            #If the letter is found            if letter == word[l]:                #Add 1 to letterCount                letterCount += 1                #Add the guess to the list of correct guesses                if not isInWord(letter,guesses):                                    correctGuesses.append(letter)                                    guesses.append(letter)        #Return the time the letter was found        return letterCount    else:            if not isInWord(letter,guesses):                guesses.append(letter)                incorrectGuesses.append(letter)            return 0#Ask the user to input a letterdef getLetter ():    letter = input(Please enter a letter )    #Make sure it's actually a letter(is not a number)    x = letter    if isNumber(x):        print (Invalid)        return getLetter()    #Make sure it's only one letter    #If it's a word it's ok, that will be chacked later    if len(letter) == 0:        print(Invalid)        return getLetter()    #If everything is ok, return the letter    return letter#A function to print the word based on correct guessesdef printWord(word,guesses):    #define a printout variable    printout =     #loop through each letter in the word to check it against the guesses    for i in range(0,len(word)):        if word[i] in guesses:            #if there's a match add the letter to the printout            printout += word[i]        else:            #otherwise fill it with an _            printout += _    return printout#Check if word is completedef checkWord(word,guesses):    if word == printWord(word,guesses):        return True    else:        return False#While the word is not complete keep asking for an inputwhile checkWord(word,correctGuesses) == False:    #Terminate while loop if there are to many incorrect guesses    if len( incorrectGuesses ) > incorrectGuessesMax:        print (Too many incorrect guesses, the word was:  + word)        break    #Receive an input    guess = getLetter()    #Chack if the input was a letter or word    if len(guess) > 1:        #Check if the guess is equal to the word        if guess == word:            #Inform the user of their success            print(Well Done, You guessed the word correctly in  + str(len(guesses)) +  guesses!)            #Terminate the loop            break        else:            print(guess +  is not the word you are looking for)    else:        #Print how many letters are correct        print(str(timesInWord(guess,word)) +  out of  + str(len(word)))    #Print letter guesses    print (Your guesses are:  + str(guesses))    #Print the amount of guesses left    guessesLeft = incorrectGuessesMax - len(incorrectGuesses)    guessesLeft += 1    print (You have  + str(guessesLeft) +  incorrect guesses left)    #Print the current state of the word based on correct guesses    print(printWord(word,correctGuesses))     #Check if the word is completed    if printWord(word,correctGuesses) == word:        #Inform the user of their success        print(Well Done, You guessed the word correctly in  + str(len(guesses)) +  guesses!)        #Terminate the loop        break
Python Hangman Console
python;beginner;game;console;hangman
The first thing that strikes me with your code are the comments: there are way too many comments. There are especially too many comments considering that your code rather well self-documented. For example, you could remove all the comments in the following snippets since they don't add any value to the code and provide no more information than the variables' names:#Make the word lower caseword = word.lower()#Make a list of guessesguesses = []#Make a list of correct guessescorrectGuesses = []#Make a list of incorrect guessesincorrectGuesses = []#Set a maximum number of incorrect guessesincorrectGuessesMax = 7Self-documenting code is viewed as good by the Python style guide (known as PEP8) and the Zen of Python even says that:Explicit is better than implicit.The PEP8 explicitely says that comments that contradicts the code (that's often the case when you modified the code but not the comments) is worse than no commentsThe function isInWord can actually be simplified to:letter.lower() in wordAll the other checks are not really useful. The first check to check whether the letter is in the alphabet is not really useful, because the letter cannot be in the word in the first place if it is not in the alphabet (unless you did something wrong, but if you did something wrong, it will be simpler to read a meaningful error message).This piece of code is rather misleading:for l in range(0,len(word)):    #If the letter is found    if letter == word[l]:It is not a good idea to name a variable l. When I read word[l], I was convinced that it was written word[1]. Try to avoid as much as possible variable names that can be read as numbers such as l, o, l2, lo, etc...This piece of code could be improved:#Make sure it's actually a letter(is not a number)x = letterif isNumber(x):    print (Invalid)    return getLetter()If you want to check whether a one character string is a letter, you better you the method isalpha from the class str:if not letter.isalpha():    print(Invalid)    return getLetter()Therefore, you can totally get rid of the function isNumber since it is not used anywhere else.