Newbie: Explain My Problem

Robert Kern rkern at ucsd.edu
Wed Jun 29 08:48:59 EDT 2005


John Machin wrote:
> 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.

3. Sign up for the Python-tutor list. (Okay, that's not quite "helping 
yourself," but it's still good advice, I think).

http://mail.python.org/mailman/listinfo/tutor

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list