python script to give a list of prime no.
Sathvik Babu Veligatla
sathvikveligatla at gmail.com
Sun Apr 5 09:01:07 EDT 2020
On Sunday, April 5, 2020 at 6:04:20 PM UTC+5:30, Orges Leka wrote:
> You can try the following:
> It is based on trial division and very slow, compared to the state of the
> art:
>
> import math
> def is_prime(n):
> if int(math.sqrt(n))**2 == n:
> return(False)
> for i in range(2,int(math.ceil(math.sqrt(n)))):
> if n%i==0:
> return(False)
> return(True)
>
> then:
>
> primes = [x for x in range(1,1000) if is_prime(x)]
>
> print(primes)
>
> Kind regards,
> Orges
>
> Am So., 5. Apr. 2020 um 14:27 Uhr schrieb Sathvik Babu Veligatla <
> sathvikveligatla at gmail.com>:
>
> > hi,
> > I am new to python, and i am trying to output the prime numbers beginning
> > from 3 and i cannot get the required output.
> > It stops after giving the output "7" and that's it.
> >
> > CODE:
> > a = 3
> > l = []
> > while True:
> > for i in range(2,a):
> > if a%i == 0:
> > l.append(1)
> > else:
> > l.append(0)
> >
> > if l.count(1) == 0:
> > print(a)
> > a = a + 2
> > elif l.count(1) >> 0:
> > a = a + 2
> >
> >
> >
> > Any help is appreciated,
> > Thank you.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
>
>
> --
> Mit freundlichen Grüßen
> Herr Dipl. Math. Orges Leka
>
> Mobil: 015751078391
> Email: orges.leka at googlemail.com
> Holzheimerstraße 25
> 65549 Limburg
umm, first of all, thank you for the quick response.
But, I am basically trying to get the output using the simplest means possible(beginner's trial :-)). So can you try to run it tell me, why it isn't working?
thank you.
More information about the Python-list
mailing list