Calculating primes in Python