To find first N prime numbers in python

前端 未结 29 2269
醉梦人生
醉梦人生 2020-11-28 06:56

I am new to the programming world. I was just writing this code in python to generate N prime numbers. User should input the value for N which is the total number of prime n

29条回答
  •  暖寄归人
    2020-11-28 07:39

    Try using while loop to check the count, that is easy. Find the code snippet below :

    i=1
    count = 0;
    x = int(input("Enter the number:\n"))
    while (count < x):
    c=0
    for j in range (1, (i+1), 1):
        a = i%j
        if (a==0):
            c = c+1
    
    if (c==2):
          print (i)
          count = count+1
    i=i+1
    

提交回复
热议问题