[Tutor] help with prime number program

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Nov 1 05:34:05 CET 2005



On Mon, 31 Oct 2005, Kent Johnson wrote:

> Norman Silverstone wrote:
> > I am a beginner so, I hope what I give, makes sense. In it's simplest
> > form what is wrong with :-
> >
> > n = input("Enter a number")
> > if n % 2 != 0 and n % 3 != 0:
> >    print n, " Is a prime number"
> >
> This only gives the correct answer if n < 25. You can't test against a
> fixed list of divisors, there will always be a non-prime whose divisors
> are not in your list.

Kent's comment is actually a paraphrase of Euclid's "There are an infinite
number of primes" argument used in mathematics.  *grin*

    http://mathworld.wolfram.com/EuclidsTheorems.html




More information about the Tutor mailing list