Skip to content Skip to sidebar Skip to footer

How Do I Detect The Repeat Input In My Hangman Game (python)!

I am facing the problem that how to detect the repeat input in my Hangman Game. Please help me! Here is my code:(First i call the function for the game. And i use while loop) d

Solution 1:

Can you try the following code:

defcheckValidGuess():

    if guessword in guess:
        print("Repeat")

    elif guessword in num:
        print("You can only input letter a-z")
        print("Try again")

    eliflen(guessword) > 1:
        print("You can only guess one letter at a time!")
        print("Try again")


defcheckPlayerWord():
    if guessall == word:
        print("Well done")
    else:
        print("Uh oh!")


defcheckLetterInWords():
    if guessword.lower() in word:
        print("Well done!", guessword, "is in my word")
    elif guessword.lower() notin word and guessword.lower() notin num:
        print("Try again")


choose = input("Enter your choice:")
readFileWords()
time = 10
word = getRandomWord()
guess = [] # list to store the input valueswhile time != 0and word:
    print("You have", time, "guesses left.")
    guessword = input("Guess a letter or enter '0''to guess the word:")  # This is user input to guess the letter    
    num = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    checkValidGuess()
    guess.append(guessword) # appending the input to listif guessword == "0":
        guessall = input("What is the word: ")
        checkPlayerWord()
    else:
        checkLetterInWords()

The guess = [] must be declared outside the loop, otherwise for every iteration it will create a new list

Post a Comment for "How Do I Detect The Repeat Input In My Hangman Game (python)!"