Note that there are some explanatory texts on larger screens.

plurals
  1. POHangman program in python 3.x
    primarykey
    data
    text
    <pre><code>print("Welcome to Hangman! Guess the mystery word with less than 6 mistakes!") words= ['utopian','fairy','tree','monday','blue'] i=int(input("Please enter a number (0&lt;=number&lt;10) to choose the word in the list: ")) if(words[i]): print("The length of the word is: " , len(words[i])) guess=input("Please enter the letter you guess: ") if(guess in words[i]): print("The letter is in the word.") else: print("The letter is not in the word.") guesses=1 while guesses&lt;6: guess=input("Please enter the letter you guess: ") if(guess in words[i]): print("The letter is in the word.") guesses=guesses+1 else: print("The letter is not in the word.") guesses=guesses+1 if guesses==6: print("Failure. The word was:" , words[i]) </code></pre> <p>Just started on this Hangman program in python. I'm doing this on a step by step based on a set of instructions and I'm at the point where I want to write some simple code that checks whether the letter entered is found in the chosen word at all. I'm ignoring the position of the matches, only concerned with counting the number of bad guesses. So far so good it seems, but I've encountered a small but big (if that makes sense) problem. On the sixth <strong>bad</strong> guess I want the loop to finish and let the user know that they failed and the computer won. I noticed that in my case the loop finishes once the user has entered their sixth guess, whether it be bad or good. So if the word is 'fairy' or whatever, no matter how many correct letters that the user guessed the loop will finish regardless on their 6th go. I want the loop to finish only when the user has entered six bad guesses, so in the example of the word 'fairy' if the user inputs 'f' which would be correct and if the next six guesses are incorrect the "failure" message will be printed as opposed to what I have now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload