User:Ixo/Project/primes.py

From OLPC
< User:Ixo‎ | Project
Revision as of 03:56, 19 February 2008 by Ixo (talk | contribs) (new page prime numbers)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

  1. Example for pippy activity
  2. Finding those elusive primes
  3. 20080218, ixo on wiki.laptop.org

print "Prime numbers are only evenly divisible by 1 and itself." print "How many prime numbers do you want (2 or more)? 100 "

print "1 2 ",

primes_found = 2 number = 3;

while primes_found < 100:

    limit_check = number/4;  # should be square_root
    check_factor = 2;
    factor_found = False
    while ((check_factor <= limit_check) and (not factor_found)):  
    	div = round(number / check_factor)
    	factor = div * check_factor;
       if factor == number:
           factor_found = True
       check_factor = check_factor + 1
    if not factor_found :
           primes_found = primes_found + 1
           print number,
    number = number + 1

print " .. done."