defprime_number(n):
c =0for x inrange(2, n):if n % x ==0:
c = c +1return c
n =int(input("Enter a number = "))if prime_number(n)==0:print("Prime number.")else:print("Not prime number.")
from math import sqrt
for i inrange(2,int(sqrt(num))+1):if num % i ==0:print("Not Prime")breakprint("Prime")# Note: Use this if your num is big (ex. 10000 or bigger) for efficiency# The result is still the same if the num is smaller
import math
prime =int(input("Enter your number: "))
count =0
sqr =int(math.sqrt(prime))for i inrange(2, sqr+1):if prime % i ==0:print("your number is not prime")
count +=1breakif count ==0:print("your number is prime")
a=int(input('print number:'))for i inrange(2,a):if a%i !=0:continueelse: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")
#prime number gen
nums=[]max=10000classN:defcrazy():for i inrange(max):
nums.append(True)
nums[0]=False
nums[1]=Falsefor index inrange(max):if nums[index]:
current_multiple =2while index*current_multiple <max:
nums[index*current_multiple ]=False
current_multiple +=1for index inrange(max):if nums[index]:print(f"----> {index} is a prime #")
N.crazy()
defprime_checker(number):
is_prime =True#use a bool to flag prime numberfor i inrange(2, number):# starts at 2 and loops until the range of numberif number % i ==0:# if is divisible not a prime
is_prime =Falseif 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
defprime_checker(number):
is_prime =Truefor i inrange(2, number):if number % i ==0:
is_prime =Falseif 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)
#prime number verification program
a=int(input('print number:'))for i inrange(2,a):if a%i !=0:continueelse: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.
# Thanks to https://www.codegrepper.com/profile/farid# Just tune his answer into easy to use functiondefprime_numbers(start_num, end_num):for number inrange(start_num , end_num +1):
is_prime =Truefor counter inrange(2,number):
value = number % counter
if value ==0:
is_prime =Falsebreakif is_prime ==True:print(number)
# Prime number:
n =int(input("Please enter your input number: "))if n>1:for i inrange(2,n):if n%i ==0:print("%d is a Not Prime."%n)breakelse: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))
'''
# This shows how we can use for + else using a break in betweenfor x inrange(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 inrange(2, x):if x % i ==0:print(x,"is not a prime number.")breakelse: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.
defprime(n):if n>1:if n==2or n==3:print("it is a prime number")for i inrange(2,int(n/2)+1):if n%i==0:print("it is not a prime number")breakelse:print("it's a prime number")breakelse:print("it is not a prime number")
start_num , end_num =input("enter 2 number sepreted by ,:").split(",")
start_num , end_num =int(start_num),int(end_num)for number inrange(start_num , end_num+1):
is_prime =Truefor counter inrange(2,number):
value = number % counter
if value ==0:
is_prime =Falsebreakif is_prime ==True:print(number)
'''Write a Python script that prints prime numbers less than 20'''print("Prime numbers between 1 and 20 are:")
ulmt=20;for num inrange(ulmt):# prime numbers are greater than 1if num >1:for i inrange(2,num):if(num % i)==0:breakelse:print(num)
prime=int(input("Enter a number:"))buffer=0for i inrange(2,prime):if prime%i==0:print(prime," is not a prime number")buffer=1breakifbuffer==0:print(prime," is a prime number")