+ 1
How to find the n'th prime number of the mathematical prime number series?
I looking for a python script that gives me the nth prime number. Input : n value output: nth prime number dummy data: input: 2 output: 3 explanation: as we now the prime number series is 2, 3, 5, 7, 11,...... so the 2nd number is 3
8 Answers
+ 3
You could probably create an array with those primes and then just take his index...
+ 2
Here in Sololearn is against rules to ask others do a code for you...đ
Moreover python is not my cup of tea...â
+ 1
In Python, arrays are called lists.
You can learn about lists in SoloLearn's Python Tutorial:
https://www.sololearn.com/Course/Python/?ref=app
Lists are covered just after Basic Concepts, in Control Structures parts 7-9
+ 1
Use the sieve of Eratosthenes to create a list of all the prime numbers. Then you just use the adress of the list at adress n to get the nth prime. You will find some examples here.
https://www.sololearn.com/learn/969/?ref=app
The trick is to know how far to take the sieve in order to ensure that you go past n. for that you may use the Prime-counting function.
http://en.m.wikipedia.org/wiki/Prime-counting_function
+ 1
So you read the rules and ignore them anyway but other people are supposed to care about your 'rule' ('Python')? :-p
Anyway, if you don't want to use a list but calculate the n, you could go with a counter variable.
counter = 0
and then, when your for-loop or whatever finds a prime number:
counter += 1
And when counter == int(input), you hand out the result.
0
can you do it ?
0
can you do it ?
0
when I am posting this to Sololearn forum means I know the rules. and I mentioned python so... đ