[SciPy-user] prime numbers

Walter Mudzimbabwe walter@aims.ac...
Thu Oct 23 07:28:40 CDT 2008


can anybody help me figure out why the following program cannot produce
primes upto 10.
--------------------------------------------------
from scipy import *

def isdivisible(n,listt):
   for i in range(len(listt)):
       if (n%listt[i]==0):
           return 1
       else:
           return 0

def primes_upto(m):
   u=[1,2]
   for i in range(3,m+1):
        if (isdivisible(i,u[1:])==0):
           u.append(i)
   return u

print primes_upto(10)
-----------------------------------------------------
it's output is:

[1, 2, 3, 5, 7, 9]



-- 
Walter Mudzimbabwe (Formerly with AIMS)
University of Western Cape.
Mathematics Dept,
Private Bag X17,
7535 Bellville,
RSA

Contact :+27 78 5188402
         mudzmudz@gmail.com

"Those of many tricks take them to the grave".......waltermudz20008






More information about the SciPy-user mailing list