Simple prime number generator in Python

前端 未结 26 2143
感情败类
感情败类 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条回答
  •  萌比男神i
    2020-11-22 07:54

    How about this if you want to compute the prime directly:

    def oprime(n):
    counter = 0
    b = 1
    if n == 1:
        print 2
    while counter < n-1:
        b = b + 2
        for a in range(2,b):
            if b % a == 0:
                break
        else:
            counter = counter + 1
            if counter == n-1:
                print b
    

提交回复
热议问题