Python program to print the prime numbers
kw.py
import sympy print(list(sympy.primerange(2,50)))
kw.py
lst=[] for n in range(2,50): if all(n%i!=0 for i in range(2,n)): lst.append(n) print(lst)
kw.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)
kw.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
kodingwindow@kw:~$ python3 kw.py [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
Comments and Reactions
What Next?
Python program to find the factorial of a given number
Python program to print the sum of all digits in a given number
Python program to print the multiplication table of a given number
Advertisement