User:Ixo/Project/primes.py: Difference between revisions
Jump to navigation
Jump to search
(new page prime numbers) |
m (come on formatting) |
||
Line 1: | Line 1: | ||
<pre> |
|||
<code> |
|||
# Example for pippy activity |
# Example for pippy activity |
||
# Finding those elusive primes |
# Finding those elusive primes |
||
Line 33: | Line 32: | ||
print " .. done." |
print " .. done." |
||
</ |
</pre> |
Latest revision as of 03:59, 19 February 2008
# 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."