lundi 20 juin 2016

Prime number printer stops at 251, why?


I started learning Python today, and I came up with the idea of creating a program that prints all the prime numbers from 0 to 10 000. I managed to make my program print out all primes until 251, at which point it stops printing out numbers. Why does it do this?

Here is the code:

for numberToCheck in range(2,10000):
    divider = 2
    while numberToCheck > divider:
        if numberToCheck % divider is 0:
            break
        else:
            divider += 1
    if numberToCheck is divider:
        print(numberToCheck, "is a prime number.")

Aucun commentaire:

Enregistrer un commentaire