0
def guess():
    while True:
        try:
            guess = raw_input("Guess your letter")
            if len(guess) != 1 or guess.isdigit() == True:
                print "Please guess again"
            if len(guess) == 1 and  guess.isdigit() == False:
                guessed.append = guess
                return guess
                break
        except StandardError:
            pass

print guess()

this loop keeps repeating no matter what value I put in the raw input. Why???

3
  • 1
    probably because guessed.append = guess raises an error. Can't be sure because you don't tell us what guessed is Commented May 30, 2013 at 22:22
  • Other people have diagnosed your problem already, but it's probably worth noticing that your break statement is unreachable (and therefore worthless). Commented May 30, 2013 at 22:39
  • try,except statements often hide real errors. Why are you using one? it seems like you already have error catching in the form of your if statements? Commented May 30, 2013 at 23:00

2 Answers 2

2

Because guessed.append = guess wil raise an error every time len(guess) == 1 and guess.isdigit() == False is True and then the control will go to the except block which is going to restart the loop again.

If you've defined guessed somewhere in your code then I think you probably wanted to do this:

guessed.append(guess)

Otherwise define guessed first.

Sign up to request clarification or add additional context in comments.

Comments

1

Every time you try to execute the line guessed.append = guess you raise a StandardError, so the line telling you to return guess is never executed.

To fix it you should define guessed outside the function, and correct the line to guessed.append(guess).

Also note that the line break right after return guess would never be executed even if you fixed this bug.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.