[Tutor] what? (late nite entertainment) (*)

Alfred Milgrom fredm at smartypantsco.com
Wed Jan 28 18:57:08 EST 2004


Hi Gregor:

Hard to work out what is what :) as there seems to be a typo in one line of 
your code:

        if x[z]: x[z*z:n:z]=y[z*z:n:z]

(At least it doesn't work on my machine with Python 2.2)
And unfortunately I can't guess what this line is supposed to be :((

Also the subroutine breaks for n = 1 or less.
Maybe you need a line at the start to say
         if n <2 : return [0]

Fred

At 11:33 PM 28/01/04 +0100, Gregor Lingl wrote:
>What is this? Another version of the well known ...
>
>def what(n):
>    x,y = range(n), [0]*n
>    x[1]= 0
>    z = 0
>    while z*z <= n:
>        z+=1
>        if x[z]: x[z*z:n:z]=y[z*z:n:z]
>    return [z for z in x if z]
>
>Regards,
>Gregor
>
>(*) at least in good old Europe





More information about the Tutor mailing list