Github :-

source

## #25 Python Tutorial for Beginners | Prime Number in Python

Add to favorites

Add to favorites

Github :-

source

Rohit nainOctober 2, 2020 at 9:52 amuser_input = int(input("Enter your number:"))

for i in range(2,user_input):

if (user_input % i == 0):

print(user_input, "is not a prime number")

break

else:

print(user_input, "is a prime number")

Rahul MishraOctober 2, 2020 at 9:52 amnum = int(input("Enter a number "))

for i in range(2,num):

if num % i == 0:

print(num , " is not a prime number.")

break

else:

print("Prime")

Nicole AngelaOctober 2, 2020 at 9:52 amlove this! thanks for the info!

ZESHAN KHALIDOctober 2, 2020 at 9:52 am#checking whether number is prime or not by getting user input

num =int(input("Enter your expected number "))

for i in range(2,num):

if num%i==0:

print("Not prime number ")

break

else:

print("Prime number ")

break

Wilbert LoOctober 2, 2020 at 9:52 amCan someone help me if i input 5 the output is 2 3 5 7 11 do you know how?? If you know pls help me i am stuck

Nitin KumarOctober 2, 2020 at 9:52 amn = int(input("Enter a Number : "))

flag = 0

for i in range(2, n):

if n % i == 0:

flag = 1

break

if flag == 1:

print(n , " is not a Prime Number")

else:

print(n , " is a Prime Number")

Amit chakrabortyOctober 2, 2020 at 9:52 amSuppose i want to print the dividends also(if not prime) . how can i do that ?? help needed

Dip PaulOctober 2, 2020 at 9:52 am1 is not a prime num… but in ur code if i put 1… Output 1 is prime num. Just add one code between 1st line nd 2nd line that is if num >1:

Entertain mentOctober 2, 2020 at 9:52 amThen every number is prime sir

Entertain mentOctober 2, 2020 at 9:52 amEvery number is divisible by 1 and by number itself

tony gowthamOctober 2, 2020 at 9:52 amdef check_prime(n):

if n == 1:

return False

elif n == 2:

return True

else:

for i in range(2,n):

if n % i == 0:

return False

return True

Tankasala AishwaryaOctober 2, 2020 at 9:52 amfrom math import sqrt

n = int(input('Enter a number: '))

if n%2==0 and n!=2:

print('Not Prime')

else:

for i in range (3,int(sqrt(n))+1,2):

if n%i==0:

print('Not Prime')

break

else:

print('Prime')

chandrashekhar TigercharlaOctober 2, 2020 at 9:52 amImport math

X = int (input("please enter a number: "))

For I in range (2,math.ceil(x/2)):

If x % i ==0:

Print (" it's not a prime ")

Break

Else:

Print ( " its a prime number")

Raju ChowdaryOctober 2, 2020 at 9:52 amr=int(input("Enter your number:-"))

for k in range(2,r):

if r%k==0:

print("=> Not Prime")

break

else:

print("=> Prime")

Vishal GawhaneOctober 2, 2020 at 9:52 amBoss Ur amazing person …

vishal vinayakOctober 2, 2020 at 9:52 ami=int(input("Enter the no to be checked:"))

a=0

for b in range (1,i):

if i%b==0:

a=a+1

if a>=2:

print("Not Prime")

else:

print("prime")

SHAHNAWAZ KHANOctober 2, 2020 at 9:52 amI know sir aapka mood theek nhi h is video m🙁

urvish pipariyaOctober 2, 2020 at 9:52 amN = int(input ("enter a number')

If n % 2 == 0:

Print ("prime)

Else

Print (not prime)

bhanu sachdevaOctober 2, 2020 at 9:52 amthanks Navin….Brilliant teaching method….Kudos

Sou HaechanOctober 2, 2020 at 9:52 amhow do you do it without break?

Dr.MashupOctober 2, 2020 at 9:52 amnum =int(input('enter a no to check'))

for i in range(2,int(num/2)+1):

if num % i ==0:

print(' not prime')

break

else:

print('prime')

Atharv PathakOctober 2, 2020 at 9:52 amhow to check for a series or range of numbers? Like, if we don't want to give a specific number as input and we want to check all the numbers from 2-100 if prime or not. So what changes would be there in the code, could someone pls help?

Swapnil PatilOctober 2, 2020 at 9:52 amnum = int(input())

if num > 2:

for i in range(2, num):

if num % i == 0:

print("NOT Prime")

break

else:

print("Prime")

else:

print("Not prime")

Mr. NobodyOctober 2, 2020 at 9:52 amThis works too. Its with while loop. My classes havent reached till for loop yet and i was asked to make it so i made with while loop.

while True:

a=int(input('Enter the number'))

c=int(a/2)

b=2

while b<=c:

if a%b==0:

print('Composite')

break

b=b+1

else:

print('Prime')

gautam tiwariOctober 2, 2020 at 9:52 amcan any1 explane me this line : "" for i in range(2,num): ""

Sibgatullah ShovonOctober 2, 2020 at 9:52 am@telusko: Navin sir , as per condition

for i in range(2,num):

if num % i ==0:

print("not prime")

If input num is 2 then num%i==0

So, as per condition it should be not prime though we know it is prime number and python also say so. Could you please explain????