Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

prime number in python

def prime_number(n):
    c = 0
    for x in range(2, n):
        if n % x == 0:
            c = c + 1
    return c


n = int(input("Enter a number = "))
if prime_number(n) == 0:
    print("Prime number.")
else:
    print("Not prime number.")
Comment

identify prime numbers python

import math
prime = int(input("Enter your number: "))
count = 0
sqr = int(math.sqrt(prime))
for i in range(2, sqr+1):
    if prime % i == 0:
        print("your number is not prime")
        count += 1
        break
if count == 0:
    print("your number is prime")
Comment

prime number in python

a=int(input('print number:'))
for i in range(2,a):
    if a%i !=0:
        continue
    else:
        print("Its not a prime number")
        break # here break is exicuted then it means else would not be exicuted.
else:
    print("Its a prime number")
Comment

prime number program in python

def prime_number(a):
    for i in range(2,a):
        if a%i == 0:
          return False
    return True
n = int(input("Enter a number = "))
print(prime_number(n))
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

find a prime number in python

def prime_checker(number):
    is_prime = True #use a bool to flag prime number
    for i in range(2, number):# starts at 2 and loops until the range of number
        if number % i == 0:# if is divisible not a prime
            is_prime = False
    if is_prime == True:
        print(f"{number} is a prime number")
    else:
        print(f"{number} is a not a prime number.")

n = int(input("Check this number: "))#check a number for prime
prime_checker(number=n)#call the function
Comment

create prime number python

def prime_checker(number):
    is_prime = True
    for i in range(2, number):
        if number % i == 0:
            is_prime = False
    if is_prime:
        print("It's a prime number.")
    else:
        print("It's not a prime number.")

n = int(input("Check this number: "))
prime_checker(number=n)
Comment

get prime number python

from num_tool import is_prime
print(is_prime(3))

#returns True because 3 is a prime
Comment

prime number in python

import math
a=[i for i in range(2,int(input('prime number range'))) if 0 not in [i%n for n in range(2,int(math.sqrt(i)))]]
print(a)
Comment

prime number python program

#prime number verification program
a=int(input('print number:'))
for i in range(2,a):
    if a%i !=0:
        continue
    else:
        print("Its not a prime number")
        break # here break is exicuted then it means else would not be exicuted.
else:
    print("Its a prime number")#this is out of the for loop suite.
        
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 number in python


# Prime number:

n = int(input("Please enter your input number: "))
if n>1:
    for i in range(2,n):
        if n%i == 0:
            print("%d is a Not Prime."%n)
            break
    else:
        print("%d is a Prime."%n)
else:
    print("%d is a Not Prime."%n)
    
# Use to Definition Function:

'''
def Prime_number_chcek(n):
    if n>1:
        for i in range(2,n):
            if n%i == 0:
                return ("%d is a Not Prime."%n)
        return ("%d is a Prime."%n)
    return ("%d is a Not Prime."%n)

# Main Driver:
if __name__=="__main__":
    n = int(input("Enter your input number: "))
    print(Prime_number_chcek(n))
'''
Comment

prime number in python

# This shows how we can use for + else using a break in between

for x in range(1,101):
# if you want to find whether a user input is a prime number
# use the following insted of the first for loop
# x = int(input("Type a number: "))
    for i in range(2, x):
        if x % i == 0:
            print(x, "is not a prime number.")
            break
    else:
        print(x, "is a prime number.")

# This will print all the numbers from 1-100,
# in the same line will print whether it is a prime or not

# if you use the user input method
# when you type 9, the output will be:
# 9 is not a prime number.

# when you type 7, the output will be:
# 7 is a prime number.
Comment

prime number using python

def prime(n):
    if n>1:
        if n==2 or n==3:
                print("it is a prime number")
        for i in range(2,int(n/2)+1):
            if n%i==0:
                print("it is not a prime number")
                break
            else:
                print("it's a prime number")
                break
    else:
        print("it is not a prime 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 number in python

a=int(input("Enter number: "))
k=0
for i in range(2,a//2+1):
    if(a%i==0):
        k=k+1
if(k<=0):
    print("Number is prime")
else:
    print("Number isn't prime")
Comment

prime number in python

start_num , end_num = input("enter 2 number sepreted by ,:").split(",")
start_num , end_num = int(start_num) , int(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 number in python

'''Write a Python script that prints prime numbers less than 20'''

print("Prime numbers between 1 and 20 are:")
ulmt=20;
for num in range(ulmt):
   # prime numbers are greater than 1
   if num > 1:
       for i in range(2,num):
           if (num % i) == 0:
               break
       else:
           print(num)
Comment

prime number in python

prime=int(input("Enter a number:"))
buffer=0
for i in range(2,prime):
    if prime%i==0:
        print(prime," is not a prime number")
        buffer=1
        break
if buffer==0:
    print(prime," is a prime number")
Comment

PREVIOUS NEXT
Code Example
Python :: write to file python 3 
Python :: remover espaços string python 
Python :: python namedtuple 
Python :: usong brave browser pyhton 
Python :: jupyter themes 
Python :: how to add and subtract days datetime python 
Python :: polarean share price 
Python :: add path python sys 
Python :: matplotlib add legend axis x 
Python :: get variance of list python 
Python :: django populate choice field from database 
Python :: convert 2d list to 1d python 
Python :: python dict order a dict by key 
Python :: django foreign key error Cannot assign must be a instance 
Python :: save pandas into csv 
Python :: python string exclude non alphabetical characters 
Python :: python save .mat 
Python :: how to print alternate numbers in python 
Python :: python split tuples into lists 
Python :: can you edit string.punctuation 
Python :: convert series to datetime 
Python :: pyqt display math 
Python :: load static files in django 
Python :: supprimer ligne python dataframe 
Python :: SafeERC20: low-level call failed 
Python :: How to Create a Pie Chart in Seaborn 
Python :: how to auto update chromedriver selenium python 
Python :: python datetime into 12-hour format 
Python :: change column value based on another column pandas 
Python :: researchpy correlation 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =