User:Ixo/Project/primes.py
Jump to navigation
Jump to search
- Example for pippy activity
- Finding those elusive primes
- 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."