Finding the nth prime number using Python
By : user2356486
Date : March 29 2020, 07:55 AM
I hope this helps you . See the hints given by MIT for your assignment. I quote them below: code :
def primes(n):
# http://stackoverflow.com/questions/2068372/fastestwaytolistallprimesbelowninpython/3035188#3035188
""" Returns a list of primes < n """
sieve = [True] * n
for i in xrange(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((ni*i1)/(2*i)+1)
return [2] + [i for i in xrange(3,n,2) if sieve[i]]

Finding if a number is prime using Python
By : user3253114
Date : March 29 2020, 07:55 AM
Does that help Your problem is that you never eliminate the last number in numbers. If range_number is 21, then len(numbers) is 20 and len(numbers)1 is 19. So this line here: code :
for n in range(i + numbers[i], len(numbers)1, numbers[i]):
for n in range(i + numbers[i], len(numbers), numbers[i]):

Python: finding the +100th prime number
By : Alejandro López
Date : March 29 2020, 07:55 AM
I hope this helps . I think you have an offbyone error. Python uses zero basedindexing, so to get the 121st element you would want to access your list at k[120]. By the way, 1 is not a prime number.

using filter and generator to generator endless prime number in python
By : Javier Perez Ferrada
Date : March 29 2020, 07:55 AM
may help you . For each prime number found a filter is applied to the iterable, the filter used is a function that excludes all multiples of the prime number. So your iterable is wrapped in as many filters as you found prime numbers, for example the number 105 is excluded because it's divisible by 3 and the filter for all multiples of 3 was added when you found the prime number 3. code :
def _odd_iter():
n = 1
while True:
n = n + 2
yield n
def _not_divisible(n):
print('add filter for all multiples of', n)
return lambda x: print('check if', x, 'is divisible by', n, 'result: ', not (x % n > 0)) or x % n > 0
def primes():
yield 2
it = _odd_iter()
while True:
n = next(it)
yield n
it = filter(_not_divisible(n), it)
for n in primes():
if n < 20:
print(n)
else:
break
2
3
add filter for all multiples of 3
check if 5 is divisible by 3 result: False
5
add filter for all multiples of 5
check if 7 is divisible by 3 result: False
check if 7 is divisible by 5 result: False
7
add filter for all multiples of 7
check if 9 is divisible by 3 result: True
check if 11 is divisible by 3 result: False
check if 11 is divisible by 5 result: False
check if 11 is divisible by 7 result: False
11
add filter for all multiples of 11
check if 13 is divisible by 3 result: False
check if 13 is divisible by 5 result: False
check if 13 is divisible by 7 result: False
check if 13 is divisible by 11 result: False
13
add filter for all multiples of 13
check if 15 is divisible by 3 result: True
check if 17 is divisible by 3 result: False
check if 17 is divisible by 5 result: False
check if 17 is divisible by 7 result: False
check if 17 is divisible by 11 result: False
check if 17 is divisible by 13 result: False
17
add filter for all multiples of 17
check if 19 is divisible by 3 result: False
check if 19 is divisible by 5 result: False
check if 19 is divisible by 7 result: False
check if 19 is divisible by 11 result: False
check if 19 is divisible by 13 result: False
check if 19 is divisible by 17 result: False
19
add filter for all multiples of 19
check if 21 is divisible by 3 result: True
check if 23 is divisible by 3 result: False
check if 23 is divisible by 5 result: False
check if 23 is divisible by 7 result: False
check if 23 is divisible by 11 result: False
check if 23 is divisible by 13 result: False
check if 23 is divisible by 17 result: False
check if 23 is divisible by 19 result: False

python  finding circular prime number
By : Ihor Shevchuk
Date : March 29 2020, 07:55 AM
With these it helps I am trying trying to find the number of circular primes from a given limit. The prime(x) will return whether a number is a prime or not. The rotations() will return a list of rotated numbers. Lastly, prime_count() will output the total amount of circular primes based on the given limit. Both prime() and rotations() gave me the correct output; however, prime_count() is not incrementing like it should. Any ideas on what i did wrong? , There are a few problems with your code: code :
In [8]: prime(1)
Out[8]: True

