0

in the code given below can someone make the code in such way that the user enters the valve for N

from math import sqrt num = 1 pcnt = 0 def prime(n): sqroot = int(sqrt(n)) j = 2 while j <= sqroot: if n % j == 0: return False j = j + 1 return True N = 420 while(True): num = num + 1 if prime(num): pcnt = pcnt + 1 if pcnt == N: print(pcnt, 'th prime is', num) break

20th Aug 2016, 9:34 AM
rajesh joshi
rajesh joshi - avatar
1 Odpowiedź
- 1
from math import sqrt N=int(input("Insert Value for 'N':\n")) num = 1 pcnt = 0 def prime(n): sqroot = int(sqrt(n)) j = 2 while j <= sqroot: if n % j == 0: return False j = j + 1 return True while(True): num = num + 1 if prime(num): pcnt = pcnt + 1 if pcnt == N: print(pcnt, 'th prime is', num) break
20th Aug 2016, 1:16 PM
Marco Romanin
Marco Romanin - avatar