+ 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

19th Aug 2018, 4:36 PM
udipta
udipta - avatar
8 Antworten
+ 3
You could probably create an array with those primes and then just take his index...
19th Aug 2018, 4:44 PM
Ledio Deda
Ledio Deda - avatar
+ 2
Here in Sololearn is against rules to ask others do a code for you...😉 Moreover python is not my cup of tea...✌
19th Aug 2018, 4:48 PM
Ledio Deda
Ledio Deda - avatar
+ 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
19th Aug 2018, 6:02 PM
Kirk Schafer
Kirk Schafer - avatar
+ 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
19th Aug 2018, 6:43 PM
Louis
Louis - avatar
+ 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.
19th Aug 2018, 8:05 PM
HonFu
HonFu - avatar
0
can you do it ?
19th Aug 2018, 4:46 PM
udipta
udipta - avatar
0
can you do it ?
19th Aug 2018, 4:46 PM
udipta
udipta - avatar
0
when I am posting this to Sololearn forum means I know the rules. and I mentioned python so... 🙂
19th Aug 2018, 4:50 PM
udipta
udipta - avatar