To find first N prime numbers in python

前端 未结 29 2352
醉梦人生
醉梦人生 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:44

    You don't need to declare that many variables, see the below code is simple and easy to understand.

    for num in range(1,50):     
       for i in range(2,num):    
          if num%i == 0:                  
             break 
       else:                 
          print(num,'is a prime')
    

    First 50 prime numbers output

提交回复
热议问题