Accenture Coding Question | Nth Prime Number | CodeWindow

Prime Numbers

A prime number is a whole number greater than 1 that is divisible only by itself and the number 1. For example, 2,3,5 etc are at prime numbers as they are divisible only by themselves and 1.

Input specification:
Input 1: An integer n.

Output Specification:
Return the nth prime.

Example 1:
Input 1: 1

Output: 2
Explanation:
2 is the first prime number.

Example 2:
Input 1: 5

Output: 11
Explanation:
Prime number series is 2,3,5,7,11,13
5th prime number is 11.

Solution in Python 3:

#https://codewindow.in
#join our telegram channel

l=int(input())
n=0
i=0
a=[]
while n<100:
    i+=1
    count=1
    for j in range(2,i):
        if i%j==0:
            count=0
            break
    
    if count==1:
        a.append(i)
        n+=1
#print(a) #to check the series
print(a[l])

# Telegram @codewindow

Output:

5
11
1
2
Recent Posts

Leave a Comment

Your email address will not be published. Required fields are marked *