[Tutor] help with prime number program
Norman Silverstone
norman at littletank.org
Mon Oct 31 15:04:06 CET 2005
> > Thank you for your comment which, if I understand you correctly, implies
> > that prime numbers greater than 25 will not be recognised. Surely, that
> > cannot be correct. However, if it is correct, could you please
> > demonstrate what you mean for my education.
>
> More precisely, it will give an incorrect answer for any non-prime that is not divisible by 2 or 3, for example 25.
>
> >>> def test(n):
> ... if n % 2 != 0 and n % 3 != 0:
> ... print n, 'is prime'
> ...
> >>> test(2)
> >>> test(3)
>
> Hmm, not looking so good for 2 and 3 either...
> >>> test(4)
> >>> test(5)
> 5 is prime
> >>> test(25)
> 25 is prime
>
> Not so sure about that one either!
How right you and Glen are and I am not very bright!! I must think
again and thanks.
Norman
More information about the Tutor
mailing list