Nested loops confusion

John Machin sjmachin at
Thu May 11 11:50:07 CEST 2006

On 11/05/2006 5:59 PM, Matthew Graham wrote:
> Thanks very much for the advice, have tidied it up and tested and seems 
> to be working as needed. 

Seems to be working? Consider where you have the expression x^2 + y^2 
... I'd like to bet that you mean "x squared" etc, not "x exclusive-or 
2" etc.

 >>> x = 3
 >>> x ^ 2
 >>> x ** 2

>  I'm still not sure what was stopping the inner 
> loop from working earlier

Call me crazy, but I thought you said it was the outer loop that wasn't 
working ...

> - but removing the redundancy in "j=0" and so 
> on seems to have solved it.

There's that "seems" word again. Removing "j=0" should have had no 
effect at all, as Dennis has pointed out. What meaning do you attach to 
"working"? Have you written any tests? Have you contemplated dropping 
the size to say 5x5 instead of 100x100 and hand-calculating the expected 

More information about the Python-list mailing list