To find first N prime numbers in python

前端 未结 29 2261
醉梦人生
醉梦人生 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条回答
  •  萌比男神i
    2020-11-28 08:02

    prime=2
    counter = 0
    x = int(input("Enter the number:\n"))
    while (counter < x):
        if all(prime%j!=0 for j in range(2, prime)):
            print(prime, "is a prime number")
            counter+=1
    
    
        prime+=1
    

提交回复
热议问题