Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python program to find first n prime numbers

n = int(input("Enter a number : "))
c = 2
while n!=0:
  for i in range(2,c):
    if c%i==0:
      break
  else:  
    print(c,end=" ")  
    n-=1
  c+=1  
Comment

first n prime number finder in python

>>> def getprimes(x):	primes = []	# Loop through 9999 possible prime numbers	for a in range(1, 10000):		# Loop through every number it could divide by		for b in range(2, a):			# Does b divide evenly into a ?			if a % b == 0:				break		# Loop exited without breaking ? (It is prime)		else:			# Add the prime number to our list			primes.append(a)		# We have enough to stop ?		if len(primes) == x:			return primes		>>> getprimes(5)[1, 2, 3, 5, 7]>>> getprimes(7)[1, 2, 3, 5, 7, 11, 13]
Comment

PREVIOUS NEXT
Code Example
Python :: import apiview 
Python :: how to make a grading system in python 
Python :: ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost) 
Python :: tkinter label border 
Python :: split data into training, testing and validation set python 
Python :: flip a plot matplotlib 
Python :: python add legend title 
Python :: python datetime string 
Python :: drop unnamed column pandas 
Python :: format python number with commas 
Python :: unix to datetime python 
Python :: simple imputer python 
Python :: python dlete folder 
Python :: python check if internet is available 
Python :: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. 
Python :: python reimport py file 
Python :: django import Q 
Python :: how to clear console python 
Python :: get current date in python 
Python :: python selenium select dropdown 
Python :: python how to generate random number in a range 
Python :: pandas drop all columns except certain ones 
Python :: python regex count matches 
Python :: how to estimate process timing python 
Python :: python get filename from path 
Python :: tkinter listbox delete all items 
Python :: tkiner border 
Python :: adding whitenoise to middleware in django 
Python :: python get current time in seconds 
Python :: python split pdf pages 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =