i=2; lst=[i**=2 while i<1000]
Carsten Haese
carsten at uniqsys.com
Tue Dec 6 11:06:59 EST 2005
On Tue, 2005-12-06 at 10:44, Steve Holden wrote:
> Daniel Schüle wrote:
> >>>i=2
> >>>lst=[]
> >>>while i<1000:
> >>> i**=2
> >>> lst.append(i)
> >>>
> >>
> >
> > unless I am missing something obvious, I can not see why the loop should
> > not terminate
>
> In that case, kindly explain how the condition i<1000 can become false
> when it starts at 2 and never changes! [In other words: you *are*
> missing something obvious].
>
> Don't you have an interpreter you could run the code in to verify that
> it does indeed loop interminably? You seem to be assuming that the
> expression i**2 changes the value of i. It doesn't.
Note that the OP wrote i**=2, not i**2.
-Carsten
More information about the Python-list
mailing list