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 :: and logic python 
Python :: speed typing test python 
Python :: how to make a operating system in python 
Python :: # get the largest number in a list and print its indexes 
Python :: extract all file in zip in python 
Python :: beautifulsoup find element containing text 
Python :: Python Switch case statement Using classes 
Python :: This code is supposed to display "2 + 2 = 4" on the screen, but there is an error. Find the error in the code and fix it, so that the output is correct. 
Python :: rezise object pygame 
Python :: ValueError: tuple.index(x): x not in tuple 
Python :: how to open link in new tab selenium python 
Python :: customize path in url 
Python :: how to use visualize_runtimes 
Python :: configure your keyboards 
Python :: how to set pywal permenent 
Python :: jupyter notebook morse code francais 
Python :: sys executable juypter is incorrect visual code 
Python :: Kernel Ridge et Hyperparameter cross validation sklearn 
Shell :: remove nginx from ubuntu 
Shell :: npm cache clean 
Shell :: expo fix dependencies 
Shell :: dotnet ef not found 
Shell :: Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE) 
Shell :: remove google chrome linux 
Shell :: Ubuntu fix broken package 
Shell :: undo commit 
Shell :: apache restart 
Shell :: install yarn global 
Shell :: remove android studio from ubuntu 
Shell :: install selenium python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =