Newbie: Explain My Problem

John Machin sjmachin at lexicon.net
Wed Jun 29 05:42:13 EDT 2005


ChuckDubya at gmail.com wrote:
[snip]
> while counter != 0:
>     if guess == num:
[snip]

Others have told you already what was wrong with your program. Here's a 
clue on how you could possibly help yourself:

1. Each time around your loop, print the values of the interesting 
objects, in this case counter and guess.
    E.g. before the "if" statement above, put something like this:
    print "guess = %r, counter = %r" % (guess, counter)
    That would have shown "guess" containing a string e.g.
    guess = '42', counter = 4
    instead of an integer e.g.
    guess = 42, counter = 4

2. Examine the logic carefully. The answer to your second problem was 
just staring you in the face -- you hadn't pulled the ripcord after the 
counter became zero.

Cheers,
John





More information about the Python-list mailing list