0

Ok, fixed that problem by putting in a break statement.
entered correct letter twice and now it won't display the statement
"has already been guessed" it was working darn it.

import random
#list of words the computer will be picking
word_list = ['python', 'jumble', 'easy', 'difficult', 'answer', 'tracer', 'muffin']

print "I'm picking one of the " , len(word_list), "words from a secret list"
random_word = random.choice(word_list)
print "Computer has selected secret word", len(random_word), "letters."

guess_count = 0
correct_guess = ""
wrong_guess = ""
previous = ""
correct = random_word


while guess_count< 5:
    guess_count+=1
    guess=raw_input("\nguess one letter ")

    if guess in previous:
       print guess, ("has already been guessed ")
       guess_count -= 1
       
    elif guess in correct:
       print guess, "is correct"
       correct_guess += guess

    else:
        print guess, "is not correct"
        wrong_guess += guess
        previous += guess

print correct_guess
print wrong_guess

print len(correct_guess), "correct guesses and", len(wrong_guess), "incorrect"

## guessing the word

print "Guess the word"
guess = raw_input ("\nYour guess:")
guess = guess.lower()
while (guess != correct) and (guess !=""):
    
   if guess != correct:
        print "Incorrect..\n"
   break
   print "Thanks for playing."     
   raw_input("\n\nPress the enter key to exit.")   
   

if guess == correct:
   print "That's it! You guessed it!\n"

print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
0

Finally got the darn thing right. Forgot to put in the previous line-
previous += guess under the elif statement.
Now have to figure how to limit my input to one letter. Currently I can enter more than 1 letter. What's the command to do that function? Can't find it in the darn book.

import random
#list of words the computer will be picking
word_list = ['python', 'jumble', 'easy', 'difficult', 'answer', 'tracer', 'muffin']

print "I'm picking one of the " , len(word_list), "words from a secret list"
random_word = random.choice(word_list)
print "Computer has selected secret word", len(random_word), "letters."

guess_count = 0
correct_guess = ""
wrong_guess = ""
previous = ""
correct = random_word


while guess_count< 5:
    guess_count+=1
    guess=raw_input("\nguess one letter ")

    if guess in previous:
       print guess, ("has already been guessed ")
       guess_count -= 1
       
    elif guess in correct:
       print guess, "is correct"
       correct_guess += guess
       previous += guess
    else:
        print guess, "is not correct"
        wrong_guess += guess
        previous += guess

print correct_guess
print wrong_guess

print len(correct_guess), "correct guesses and", len(wrong_guess), "incorrect"

## guessing the word

print "Guess the word"
guess = raw_input ("\nYour guess:")
guess = guess.lower()
while (guess != correct) and (guess !=""):
    
   if guess != correct:
        print "Incorrect..\n"
   break
   print "Thanks for playing."     
   raw_input("\n\nPress the enter key to exit.")   
   

if guess == correct:
   print "That's it! You guessed it!\n"

print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
0

In my test app, I didn't limit them to entering one letter, but I validated what they typed and complained if it was more than one character.

You could replace the raw_input and the first if test with a while loop:

while True:
    guess = raw_input("\nguess one letter ")
    guess = guess.strip().lower()
    if len(guess) > 1:
        print "Please enter only one letter"
   elif guess in previous:
        print guess, "has already been guessed "
   else:
        break

If you do, remember to change the elif guess in correct: to if guess in correct:

0

Ok I tried it enter two letters (ie aa) -
Responded back
Please enter one letter
aa
no
guess one letter
How do I prevent it from displaying the input "aa" and not even count this as on of my selections? Sorry for being picky it just doesn't feel right.

while True:
    
    guess=raw_input("\nguess one letter ")
    guess = guess.strip().lower()

    if len(guess) >1:
       print "Please enter only one letter."
    elif guess in previous:
       print guess, ("has already been guessed ")
       guess_count-=1
    else:
        break
0

When I put the while loop where it was supposed to go, I got the following from running it:

I'm picking one of the  7 words from a secret list
Computer has selected secret word 6 letters.

guess one letter er
Please enter only one letter.

guess one letter sd
Please enter only one letter.

guess one letter ght
Please enter only one letter.

guess one letter e
e is not correct

guess one letter rt
Please enter only one letter.

guess one letter r
r is not correct

guess one letter tr
Please enter only one letter.

guess one letter t
t is not correct

It looks like it is working to me.

while guess_count< 5:
    guess_count+=1

    while True:
        guess=raw_input("\nguess one letter ")
        guess = guess.strip().lower()

        if len(guess) >1:
           print "Please enter only one letter."
        elif guess in previous:
           print guess, ("has already been guessed ")
        else:
           break

    if guess in correct:
0

Here's the complete code, I still have that problem.

I'm picking one of the 7 words from a secret list
Computer has selected secret word 6 letters.

guess one letter er
Please enter only one letter.
er
no

import random
#list of words the computer will be picking
word_list = ['python', 'jumble', 'easy', 'difficult', 'answer', 'tracer', 'muffin']

print "I'm picking one of the " , len(word_list), "words from a secret list"
random_word = random.choice(word_list)
print "Computer has selected secret word", len(random_word), "letters."

guess_count = 0
correct_guess = ""
wrong_guess = ""
previous = ""
correct = random_word

while guess_count<5:
  guess_count+=1

  while True:
    
     guess=raw_input("\nguess one letter ")
     guess = guess.strip().lower()

     if len(guess) >1:
       print "Please enter only one letter."
     elif guess in previous:
       print guess, ("has already been guessed ")
       guess_count-=1
     else:
        break
       
     if guess in correct:
       print guess, "\nyes"
       correct_guess += guess
       previous += guess
     else:
        print guess, "\nno"
        wrong_guess += guess
        previous += guess

print correct_guess
print wrong_guess

print len(correct_guess), "correct guesses and", len(wrong_guess), "incorrect"

## guessing the word

print "Guess the word"
guess = raw_input ("\nYour guess:")
guess = guess.lower()
while (guess != correct) and (guess !=""):
    
   if guess != correct:
        print "Incorrect..\n"
   break
   print "Thanks for playing."     
   raw_input("\n\nPress the enter key to exit.")   
   

if guess == correct:
   print "That's it! You guessed it!\n"

print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
0

Can you use functions...you're having a hard time keeping the indenting right.

lines 31-38 should be out one indent...they need to be 'inside' the while guess_count < 5 but not 'inside' the while True

The "er no" is coming from line 36 but you're not supposed to get there until you've passed all the input tests.

I actually wrote a 'get me a letter' function and I call it from the main in my test app.

def getLetterGuess(previous):
    # Remind the user of the previous guesses if any
    if len(previous) > 0:
        print "You have already guessed:", ','.join(previous)
    # loop until we get a valid guess
    while True:
        lguess = raw_input("Guess a letter: ").strip().lower()
        if len(lguess) != 1:
            print "Enter only one character"
        elif not lguess.isalpha():
            print lguess,"is not a letter, please try again"
        elif lguess in previous:
            print "You have already guessed",lguess
        else:
            break
        print
    return lguess

Then I use it from the main like this:

# Take the Letter Guesses
for gidx in xrange(5):
    guess = getLetterGuess(previous)
    if guess in random_word:
        print "Yes,", guess, "is in the word"
        correct_guess += guess
    else:
        print "Sorry,", guess, "is not in the word"
        wrong_guess += guess
    previous += guess
0

Wish I could use it, but i'm not allowed to use the define function.
It's in the next chapter.
Wish I could life would be much easier.

0

Now it works for entering 2 characters, but something else got screwed up. See below
I'm picking one of the 7 words from a secret list
Computer has selected secret word 6 letters.
guess one letter aa
Please enter only one letter.
guess one letter e
guess one letter t
guess one letter f
guess one letter g
guess one letter y
y
no

y
0 correct guesses and 1 incorrect
Guess the word
It only gives y or n for the last letter I picked.

import random
#list of words the computer will be picking
word_list = ['python', 'jumble', 'easy', 'difficult', 'answer', 'tracer', 'muffin']

print "I'm picking one of the " , len(word_list), "words from a secret list"
random_word = random.choice(word_list)
print "Computer has selected secret word", len(random_word), "letters."

guess_count = 0
correct_guess = ""
wrong_guess = ""
previous = ""
correct = random_word

while guess_count<5:
      guess_count+=1

      while True:    
        guess=raw_input("\nguess one letter ")
        guess = guess.strip().lower()

        if len(guess) >1:
          print "Please enter only one letter."
        elif guess in previous:
          print guess, ("has already been guessed ")
          guess_count-=1
        else:
          break


if guess in correct:
   print guess, "\nyes"
   correct_guess += guess
   previous += guess
else:
   print guess, "\nno"
   wrong_guess += guess
   previous += guess

print correct_guess
print wrong_guess

print len(correct_guess), "correct guesses and", len(wrong_guess), "incorrect"

## guessing the word

print "Guess the word"
guess = raw_input ("\nYour guess:")
guess = guess.lower()
while (guess != correct) and (guess !=""):
    
   if guess != correct:
        print "Incorrect..\n"
   break
   print "Thanks for playing."     
   raw_input("\n\nPress the enter key to exit.")   
   

if guess == correct:
   print "That's it! You guessed it!\n"

print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
0

You moved the lines too far out...(sigh)

import random
#list of words the computer will be picking
word_list = ['python', 'jumble', 'easy', 'difficult', 'answer', 'tracer', 'muffin']

print "I'm picking one of the " , len(word_list), "words from a secret list"
random_word = random.choice(word_list)
print "Computer has selected secret word", len(random_word), "letters."

guess_count = 0
correct_guess = ""
wrong_guess = ""
previous = ""
correct = random_word

while guess_count<5:
      guess_count+=1

      while True:    
          guess=raw_input("\nguess one letter ")
          guess = guess.strip().lower()

          if len(guess) >1:
              print "Please enter only one letter."
          elif guess in previous:
              print guess, ("has already been guessed ")
              guess_count-=1
          else:
              break


      if guess in correct:
         print guess, "\nyes"
         correct_guess += guess
         previous += guess
      else:
         print guess, "\nno"
         wrong_guess += guess
      previous += guess

print correct_guess
print wrong_guess

print len(correct_guess), "correct guesses and", len(wrong_guess), "incorrect"

## guessing the word

print "Guess the word"
guess = raw_input ("\nYour guess:")
guess = guess.lower()
while (guess != correct) and (guess !=""):
    
   if guess != correct:
        print "Incorrect..\n"
   break
   print "Thanks for playing."     
   raw_input("\n\nPress the enter key to exit.")   
   

if guess == correct:
   print "That's it! You guessed it!\n"

print "Thanks for playing."
raw_input("\n\nPress the enter key to exit.")
0

Thanks for your patience Murtan. Everything works now finally.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.