Simple prime number generator in Python

前端 未结 26 1791
感情败类
感情败类 2020-11-22 07:16

Could someone please tell me what I\'m doing wrong with this code? It is just printing \'count\' anyway. I just want a very simple prime generator (nothing fancy).

26条回答
  •  失恋的感觉
    2020-11-22 08:19

    python 3 (generate prime number)

    import math
    
    i = 2
    while True:
        for x in range(2, int(math.sqrt(i) + 1)):
            if i%x==0:
                break
        else:
            print(i)
        i += 1
    

提交回复
热议问题