Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python program to find n prime numbers

num = 10
for i in range(2,num+1):
    for j in range(2,i):
        if(i%j == 0):
            break
    else:
        print(i)
Comment

prime numbers python

#prime number gen

nums=[]
max=10000

class N:
    def crazy():
        for i in range(max):
            nums.append(True)
        nums[0]=False
        nums[1]=False

        for index in range(max):
            if nums[index]:
                current_multiple = 2
                while index*current_multiple < max:
                    nums[index*current_multiple ]= False
                    current_multiple += 1

        for index in range(max):
            if nums[index]:
                print(f"----> {index} is a prime #")

N.crazy()
Comment

python code to print prime numbers

# Thanks to https://www.codegrepper.com/profile/farid
# Just tune his answer into easy to use function

def prime_numbers(start_num, end_num):
    for number in range(start_num , end_num + 1):
        is_prime = True
        for counter in range(2,number):
            value = number % counter
            if value == 0:
                is_prime = False
                break
        if is_prime == True:
            print(number)
Comment

prime numbers python

def is_prime(n):
  for i in range(2,n):
    if (n%i) == 0:
      return False
  return True
Comment

prime numbers upto n in python

lower = int(input("Enter lower range: "))  
upper = int(input("Enter upper range: "))  
  
for num in range(lower,upper + 1):  
   if num > 1:  
       for i in range(2,num):  
           if (num % i) == 0:  
               break  
       else:  
           print(num)  
Comment

PREVIOUS NEXT
Code Example
Python :: how to read zip csv file in python 
Python :: how to check if a network port is open using python 
Python :: calculator in one line in python 
Python :: python list add if not present 
Python :: djangodebug toolbar not showing 
Python :: pandas split dataframe to train and test 
Python :: python parser txt to excel 
Python :: python mouse click 
Python :: check if regex matches python 
Python :: mean of a list python 
Python :: create empty csv file in python 
Python :: sum of a column in pandas 
Python :: log transform pandas dataframe 
Python :: Need Clang = 7 to compile Filament from source 
Python :: runner up score hackerrank 
Python :: for idx, col_name in enumerate(X_train.columns): print("The coefficient for {} is {}".format(file_name, regression_model.coef_[0][idx])) 
Python :: how to add multiple dfs to excel sheet 
Python :: matplotlib subtitle 
Python :: how to remove first few characters from string in python 
Python :: how to take password using pyautogui 
Python :: ellipsis in python as index 
Python :: how to use an indefinite number of args in python 
Python :: python list comprehension index, value 
Python :: print console sys.stdout 
Python :: python how to create attribute of class while iterating a list 
Python :: koncemzem 
Python :: renpy scene vs show 
Python :: redis get all keys and values python 
Python :: matlab find in python 
Python :: python catch all exceptions 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =