Sunday, January 29, 2012

Python - Generating primes

I always make a generating primes program when I'm learning a new language, as if it were my "hello world". I'm using python 3.2

import math

def cribe(size):
    nums = [0]*size
    for i in range(2,int(math.sqrt(size))):
        if(nums[i] == 1):
        for j in range(2,size):
            if i * j > size - 1:
            if nums[i*j] == 0:
                nums[i*j] = 1
    for i in range(2,size):
        if(nums[i] ==0 ):
limit = input('Up to what number? ')

My IDE is by the moment aptana-studio, haven't found anything better.

No comments:

Post a Comment