At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
The simplest way to fix this code is to insert another test just before the last line: if guess == name: print 'good guess'
Thanks-- what about how to keep it from printing NOPE forever, if three wrong answers are entered, since guess is still != name?
I tried to stop the loop by telling it the top condition was met, but then I can't seem to get out of printing 'good guess.'
I would change the loop to include a test of whether 1>3. If I was writing this for the first time, I think that's ALL the loop would test.
sorry, that's whether i > 3
The idea is to give a person 3 chances to answer, then exit, so my plan would be: assign a variable to track how many chances they've had if they haven't already had all their chances get a guess add one to the number of chances they've had, because they're getting one now if the guess is wrong, tell them it's wrong if the guess is right, tell them it's right if they've had all their chances tell them they lose
sorry, the line if they haven't already had all their chances should probably actually be while they haven't already had all their chances
actually, I'd also add a line after the if their guess is right condition to increase the number of chances to the max, just so they don't get asked again.
then the if they've had all their chances should probably be if they've had all their chances and haven't gotten it right but then you'd need a variable to keep track of if they've gotten it right... Maybe just not tell them if they lose and end after the while loop stops.
How about something like this (untested, of course): good = False name = "Monty" i = 0 while (not good) and (i < 3): guess = raw_input("Guess my name") good = (guess == name) if not good: print "NOPE" if good: print "Wow--Are you telepathic or something?"
Oops. Forgot to increment i in the loop. Sorry--but I told you it was untested. :)
Thank you, I did get it to work, using your suggestions. By telling them NOPE outside the the loop, it stopped. So is there a way to tell the program just stop, you're done, don't execute any more commands? And I take it there's no such thing as GOTO anymore? guess = "" name = "Monty" i = 0 while guess != name and (i < 3): guess = raw_input("Guess my name: ") i = i + 1 if guess == name: print "good guess" if guess != name: print "NOPE. That was your last chance."
the command break inside a loop breaks that loop (but not any loops the broken loop is in). I haven't found any GOTO equivalent in Python but my experience with GOTO is that it's the command that allows me to do things I will invariably later regret.
"things I will invariably later regret" -- sometimes those also turn out to be the things we will brag about to our grandchildren... maybe not with goto though.