[Tutor] Help

Nitin Pawar nitinpawar432 at gmail.com
Tue Jul 13 12:08:32 CEST 2010


Hi,

You have two different problems
1) Easiest algorithm to find a prime number
2) and then coding the algorithm

By my knowledge,The Sieve of Eratosthenes algorithm is the fastest to find a
prime number.
The algorithm works on the basis that if a number n is prime, then all
multiples of it are not prime

so based on that you can code

Thanks,
Nitin


On Tue, Jul 13, 2010 at 3:20 PM, Dipo Elegbede <delegbede at dudupay.com>wrote:

> I was trying to write a code that prints prime numbers between 1 and 20.
>
> I have by myself seen that something is wrong with my code and also my
> brain.
>
> Could anyone be kind enough to tell me what to do....
>
> Where I am confused is how to test for other numbers without one and the
> number itself. It turns out that all numbers pass the condition I set so
> that would presuppose that all numbers are prime which is not.
>
> How exactly can I get it to run checks with other numbers such that it
> doesn't include the number itself and 1.
>
> The code is as follows:
>
> for i in range(1,20):
>
>     if float(i) % 1 == 0 and float(i) % i == 0:
>         print i, 'is a prime number'
>
>
> --
> Elegbede Muhammed Oladipupo
> OCA
> +2348077682428
> +2347042171716
> www.dudupay.com
> Mobile Banking Solutions | Transaction Processing | Enterprise Application
> Development
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100713/f95e04b9/attachment.html>


More information about the Tutor mailing list