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 < sathvikveliga...@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.l...@googlemail.com Holzheimerstraße 25 65549 Limburg -- https://mail.python.org/mailman/listinfo/python-list