Python program to print the prime numbers
codeaft.py
import sympy print(list(sympy.primerange(2,50)))
codeaft.py
lst=[] for n in range(2,50): if all(n%i!=0 for i in range(2,n)): lst.append(n) print(lst)
codeaft.py
lst=list() for n in range(2,50): prime=True for i in range(2,n): if(n%i==0): prime=False if prime: lst.append(n) print(lst)
codeaft.py
def prime(limit): lst=list() for n in range(2,limit): prime=True for i in range(2,n): if(n%i==0): prime=False if prime: lst.append(n) return lst print(prime(50))
Output
codeaft@codeaft:~$ python3 codeaft.py [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
Comments and Reactions