简体   繁体   中英

Problems with a python prime number generator

Sorry if this is obvious, but I'm quite new to python programming, why won't this program generate a list of prime numbers, most of them seem to be prime, but there are some that aren't.

#!/usr/bin/env python
print ("Prime Numbers")
Number = 2
while True:
    Test = 2
    while Test < Number:
        if Number % Test == 0:
            Number = Number + 1
        else:
            Test = Test + 1
    print (str(Number) + " is a prime number!")
    Number = Number + 1

This template should help you find the prime numbers:

    if Number % Test == 0:
        Number = Number + 1
        Test = 2 # you'll need to reset Test here
    else:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM