I am having problems with this code and im nooby what im trying to do
Create a game where the computer picks a random word and the player has to guess that word. The computer tells the player how many letters are in the word. Then the player gets five chances to ask if a letter is in the word. The computer can only respond with "yes" or "no". Then, the player must guess the word. im trying to learn python from a text book the michael dawson one
i think i didnt do a good job putting it together every letter i guess it just keeps telling me to guess

import random
print "Hello President Bush, I will give you 5 chances to guess letters of one of my secret words.\n On the final chance, you must guess the word"
WORDS = ("bush", "usa", "war", "oil", "iraq", "osama", "alla")

word = random.choice(WORDS)
print "The password is", len(word), "letters long."


guesscount = 0
done = 0
while done <=1:
    
    guess = raw_input("guess a letter: ")

    if guess in word:
        guesscount += 1
        print "yes"
        

    elif guess not in word:
        guesscount +=1
        print "no"
        
    elif guess == " ":
        print "no"
        guesscount += 1
    elif guesscount == 4:
        print "You have to guess the presidents passcode"
        guess_word = raw_input("Input code: ")
        guess_word = guess_word.lower()

        if guess_word == word:

            print "The CIA is are already at your house!\n President never gets it on    the first try..."
            break
        elif guess_word != word:

            print "President Bush did you forget your password again..."
            break

The problem is that since you have elif guesscount == 4: as a condition in an if/elif/else block, it never gets evaluated. The first two conditions are absolute:

if guess in word:
    print 'Yes'
elif guess not in word:
    print 'No'

The user's choice is either going to be present or not present... there is no possibility for the computer to evaluate past the guess not in word condition. Do you understand why?

I modified your code slightly as follows:

import random
print "Hello President Bush, I will give you 5 chances to guess letters of one of my secret words.\n On the final chance, you must guess the word"
WORDS = ("bush", "usa", "war", "oil", "iraq", "osama", "alla")

word = random.choice(WORDS)
print "The password is", len(word), "letters long."

guesscount = 0
while guesscount <= 4:
    guesscount += 1
    guess = raw_input("guess a letter: ")
    if guess in word:
        print "yes"
    elif guess not in word:
        print "no"
    elif guess == " ":
        print "no"

print "You have to guess the presidents passcode"
guess_word = raw_input("Input code: ")
guess_word = guess_word.lower()

if guess_word == word:
    print "The CIA are already at your house!\n President never gets it on the first try..."
elif guess_word != word:
    print "President Bush did you forget your password again..."

As you can see I just used the while loop to keep track of the number of guesses and moved the word guess to after the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.