Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

list of prime numbers in python

n = 20
primes = []

for i in range(2, n + 1):
	for j in range(2, int(i ** 0.5) + 1):
 		if i%j == 0:
 			break
	else:
		primes.append(i)

print(primes)
Comment

python list prime numbers

print([i for i in range(2, int(input("Enter your number: "))+1) if 0 not in [i%n for n in range(2, i)]])
Comment

how to get prime numbers in a list in python using list comprehension

>>> [x for x in range(2, 20)
     if all(x % y != 0 for y in range(2, x))]
[2, 3, 5, 7, 11, 13, 17, 19]
Comment

PREVIOUS NEXT
Code Example
Python :: python set timezone of datetime.now 
Python :: python list count() 
Python :: count of datatypes in columns 
Python :: how to round an array in python 
Python :: standard deviation python 
Python :: lambda condition python 
Python :: How to do train test split in keras Imagedatagenerator 
Python :: python find the average of a list 
Python :: # find out of the memory of the python object 
Python :: openpyxl full tutorial 
Python :: how to open a file with python 
Python :: how to change python version 
Python :: get title beautifulsoup 
Python :: user input python 
Python :: how to check how many items are in a list python 
Python :: matplotlib boxplot colors 
Python :: tkinter how to remove button boder 
Python :: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel(). y = column_or_1d(y, warn=True) 
Python :: python list splicing 
Python :: how to use global variable in python 
Python :: flask setup 
Python :: evaluate how much a python program memory 
Python :: progressbar time in python 
Python :: get json from file python 
Python :: pygame zero how to draw text 
Python :: column names pandas 
Python :: python relative file path doesnt work 
Python :: staticfiles 
Python :: hashing vs encryption vs encoding 
Python :: change tkinter app icon 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =