Sir you always simplifies the problems in a very easy way ,even a slow learner like me get the logics in first attempt.This is the real quality of great teacher.Thankyou.. Jai Hind🇮🇳
how would this code work for 2? if user enters 2, then it will satisfy the condition if x%i==0 since 2%2 =0, and it will print it's non prime number while 2 is a prime number
@@saniyakhan12939 actually the range function here is using (2,x) in that case if the value of x is also two this function will not give any output as starting is 2 and ending (which is not included in range function ) is also 2 ,[loop will start from 2 and end on 2 not including it which is not feasible] so program will work normally it will print prime as (null % i != 0)
def prime(num) ->bool: if num == 1: return False elif num == 2: return True else: ran = int(num ** 0.5) for i in range(2,ran+1): if num%i != 0: return True x= int(input("Enter Number: ")) n = prime(x) if n: print("Prime") else: print("Not Prime")
x=int(input("input your number ")) for i in range(2,int(x/2+1)): if(x%i==0): print("enter number not prime number") break; else: print("enter number is a prime numbere ") print("SIR YOU RELAY HELP US SO MUCH SO THANK YOU SOOOOOOOOOOOMUCH FOR YOUR EFFORT")
My Prime code, for checking prime number there is no need to run the loop till its number. We an even achieve it by running the loop till (num/2)+1. In this way you can reduce half of the effort. Will be useful while checking for large numbers. Code : num = int(input("check number is prime or not :")) for i in range(2,int(num/2)+1): if num % i == 0: print("not prime") break else: print("prime")
@@jatinlekhwar6798 I think you do, if you don't put 1 then it will return 4 as a prime because the range will be (2,2) and it will go into else, correct me if I am wrong
num = int(input("Enter any number ")) if num>1: for i in range(2,num): if num%i==0: print("Not a prime number.") break else: print('it is a prime number') else: print('not a prime number')
dheeraj kumar, because we don’t have to continue dividing ‘num’ by ‘i’. ‘break’ stops ‘for’. For example, ‘num’ = 10, and if 10 % 2 = 0 then this number is definitely not a prime number because prime number can only be divided by itself and by 1, and we don’t have to continue dividing ‘num’ by 3, 4 and so on. Do you understand it now?
num=int(input('enter the number')) if num%2==0 or num%3==0 or num%5==0 or num%7==0 and num%num!=0: print('not prime') else: print('prime') try this mam
Your beginner video's are best in TH-cam sir, in this lockdown wanted to be productive and thought of learning python after a lot of playlists and channels your channel has got all the information and tutorial a beginner needs
if you want to try with function: def prime(num): for i in range(2,num): if num % i == 0: return "not a prime number" else: return "prime number" num = int(input("enter a number: ")) print(prime(num))
Consider a tuple T1 = (1, 2, 5, 7, 9, 3, 4, 6, 8, 10). Write a function primes() that accepts tuple T1 as argument and creates a list T2 having values that are prime numbers in the tuple T1. The function should return a dictionary primeCubes where keys are items of the list T2 and the values are cubes of the keys. For example, when T1 as passed as an argument, T2 will be [2, 5, 7, 3] and primeCubes will be {2:8,5:125,7:343,3:27}.
import math as m x=int(input("Enter The Number :")) b=m.floor(m.sqrt(x)) for a in range(2,b+1): if a**x%x==a%x: print("The no. is prime") break else: print("Not prime") Thank You sir for your great lectures..
Little more optimized.. import math num = int(input("Enter the number:")) n = math.floor(math.sqrt(num)) for i in range(2,n + 1,1): if num % i == 0: print("The number is not prime, divisible by", i) break else: print("The number is prime")
@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????
count = 0 n = int(input("Enter a number:")) for i in range(1, n+1): if n % i == 0: count +=1 if count == 2: print(n, "is a Prime number") else: print(n, "is Not a Prime number")
num = int(input("Enter the num:")) # taking input if num < 2: print("Not prime") else: for i in range(2, num): # iterate over possible divisors if num % i == 0: print("Not Prime") break # if a divisor is found, no need to continue checking else: print("prime") Guys this will also work for 0 and 1 and also for negative numbers.
n=int(input("enter the value of n")) if(n==1): print("it is not prime number") for i in range(2,n-1): if(n%i==0): print("it is not a prime number") break else: print("it is a prime number")
at first i used to hate for loop and while loop and after watching your and seeing the examples i used to love them sir thanks a lot❤️btw i am aman raj😀
a = int(input("Enter the number = ")) count = 0 if (a>0) : if (a == 1) : print("{} is neither a prime nor a composite number.".format(a)) i = 1 while (i 2) : print("{} is a composite number.".format(a)) elif (a
♐To get code in an efficient way - just reduce the no. of iterations by half😉 code: num = 25 for i in range(2,(num//2)): if num%i==0: print("Not Prime") break else: print("Prime") o/p: not prime
@@adithyaramapuram4995 brother, you'll have to add 1 after taking the square root. if you directly put sqrt value in range, it won't get included in the code and henceforth resulting in wrong output.
from math import sqrt n = 5 for i in range(2, int(sqrt(n) + 1)): if n % i == 0: print(n, "is not a prime number") break else: print(n, "is a prime number")
I have written below code. I am implementing things after learning from your course. Thank you Sir. nums=range(1,10) for num in nums: for i in range(2,num): if num%i==0: print(num,"Not prime number") break else: print(num,"Prime number")
x= int(input('number=?')) If x==1: print('neither prime nor composite') Elif x==2: print('prime') Else: For i in range(2,x): If x%i==0: print('not prime') Break Else: print('prime') Break Print('bye')
For this program x=int(input("Enter a number")) count=0 for i in range(1,x): if x%i==0: count=count+1 if(count>2): print("The number is not prime") else: print("The number is prime")
All these days i was thinking who in the world invented this programming ?......but after watching ur videos i really feel learning programming is fun!!!
Your Python series are Great sir, Thank you so much for this ..😇 Sir i tried my best to find the time efficient manner to solve this problem 😉 Please take a look on it and give some suggestions if any.. Code: from math import sqrt n = int( input ( 'Enter a number :') ) if n==0 or n==1 : print( 'Not Prime' ) elif n==2 : print( 'Prime' ) elif n%2 ==0 : 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' )
@@mananagarwal1212 I did the correction as I didn't used editor i forgot one step.. Explanation of Code: Firstly it will check that the number is divisible by 2 or not if not then it will again check from 3,5,7,9.... till ✓n
sir this is my efficiently modified by the clue you have given 👇👇 num = 19 for i in range (2,int(num/2)): if num % i == 0: print("not prime") break else: print("prime")
lower=int(input("Enter lower limit")) upper=int(input("Enter upper limit")) for num in range(lower, upper+1): for i in range(2,num): if num%i==0: break else: print(num)
Import 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")
from math import sqrt, floor num = int(input("Give me a number..")) if num == 1: print("Not a prime") quit() else: if num == 2: print("Prime") quit() if num > 2 and num % 2 == 0: print("Not a Prime Number.") else: e = 1 + floor(sqrt(num)) for i in range(3, e, 2): if num % i == 0: print("Not a Prime Number...") break else: print("Prime Number")
for i in range(1, 20): if i % 2 != 0: print(i) This is efficient and I want to say you are a great teacher I actually learned everything i know from you. Which is only python and JavaScript but still I will learn more from you.
There is no need to iterate the for loop upto n-1 just iterate it upto n/2 Cause a number having a value more than half cannot divide that number Then the time complexity will reduce to n/2 time which is n-1 times in your code
I know this is a long code, but I think it will be easier to process. a = int(input("type here-")) b = [2, 3, 5, 7] for i in b: if a ==i: print("prime") elif a%i==0 or a==1: print("not prime") break else: print("prime")
display the prime numbers within a range x = int (input ("enter your number ? ")) y = int (input ("enter your number ? ")) for i in range (x,y): for j in range(2,i): if i%j==0: break else: print (i)
perfect channel..........!!!!!!!!!!!!!! I was totally confused with for loop and while loop, i mean didn't know to use it well..after seeing some of ur vids i was happy....and got some idea abt python language....i will see all ur python vids as it's too interesting.. btw my doubt was what is the code to print all prime numbers from 0 to 100...?
num = int(input("Enter the number: ")) factors = [] for x in range(1, num+1): if num % x == 0: factors.append(x)
# A prime number is a number which has only 2 factors one itself and second 1 # print(len(factors)) if len(factors) == 2: print(f"Congratulations {num} is a prime number, with factors only {factors}") else: print(f"Aaah! sorry {num} is not a prime number because it has factors {factors}")
my efficient way in this code user can choose its own number x=int(input('enter a number')) for i in range (2,x,1): if x%i==0: print ('not prime') break else: print (' prime')
Sir, the program you wrote is not valid if the given number is 2. Since we are starting from 2, the given number(2) will be divisible and the program will give the output as Not Prime whereas 2 is a Prime number. Any other way around this?
from math import sqrt n = int(input("Enter the number")) if n2 and n%2==0: 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")
while True: n = int(input("Please enter minimum Range")) m = int(input("Please enter maximum Range")) d = int(input("please enter range difference")) x = range(n, m, d) s = False for i in x: if i > 2: for j in range(2, i): if i % j == 0: break else: print(i) c = int(input("1 for continue 0 to end")) if c == 0: break
This 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
a=int(input('Enter number:')) check = False for i in range (2,a): if a%i == 0: print('its not a prime number') check = True break if check == False: print('Its a prime number')
num=int(input("enter the number")) for i in range(2,num): if num%i==0: print("it's not a prime no.") print("because it's divisible by",num//i,'and',num,'itself') break else: ("it,s a prime number")
sir, itsead of giving number inside code we can write a = int(input(enter a number)) for i in range(2,a): if a %i==0: print("its not a prime number") break else: print("its a prime number") print("i love telusko") out put (1) :---- output (2) :----- enter a number 11 | enter a number 12 | its a prime number | its not a prime number | i love telusko | i love telusko
a number can be divisible by itself and 1 for sure but except these it can only be divisible by the numbers ranging from 2 to upto half of that given number. so instead of checking from 2 to n we can check from 2 to n/2. def findPrime(): num = int(input("Enter a number : ")) if num == 1: return print("Not a Prime number") for x in range(2, (num // 2) + 1): if num % x == 0: print("Not a Prime number") break else: print(f"{num} is a prime number") findPrime()
a=int(input("enter number to check: ")) check=True for i in range(2,int((a/2))) : if a%i==0 : check=False break else : check=True if check==True : print("prime") else : print("not")
a = input("Which number do you want to figure out if Prime or not? ") a = int(a) b = a//2 for j in range (2,b): if a % j == 0: print(a, " is not a Prime Number") break else: print(a, " is a Prime Number")
trying efficient way...it is right sir?... def prime(num1): if num1 ==1 or num1==0: return False for i in range(3,num1, 2): if num1%i==0 or num1%2==0: return False else: return True
to print the list of prime numbers from 1 to given number n=int(input('enter the number')) list= [ ] for i in range (1,n+1): count=0 for j in range(1,i+1): if i%j==0: count+=1 if count==2: list=list+[i] print('the prime numbers are ',list)
the most simplest code sir #program to check the no. is prime n=int(input("enter the no.: ")) for i in range(1,n+1): if n%1==0 and n%i==0: print("the no. is prime") break else: print("the no. is not prime")
we can further cut the range of factors by excluding even numbers as factors of odd numbers num = int(input('enter any number')) factors_range = range(3, int(num / 2)+1, 2) if num % 2 != 0 else range(2, int(num / 2)+1, 1) for i in factors_range: if num % i == 0: print('number', num, 'is not a prime number, divisible by', i) break else: print('it is a prime number')
Sir you always simplifies the problems in a very easy way ,even a slow learner like me get the logics in first attempt.This is the real quality of great teacher.Thankyou.. Jai Hind🇮🇳
x = int (input ("enter your number ? "))
for i in range (2,x):
if x%i==0:
print ('its a non prime number')
break
else:
print ('its a prime number')
x%i ?? can you explain me this part ?
@@shafiquebarudgar8295 it is dividing x with value of i then checking its remainder is equal to 0 or not ( % equals to find remainder not percent)
how would this code work for 2? if user enters 2, then it will satisfy the condition if x%i==0 since 2%2 =0, and it will print it's non prime number while 2 is a prime number
@@saniyakhan12939 actually the range function here is using (2,x) in that case if the value of x is also two this function will not give any output as starting is 2 and ending (which is not included in range function ) is also 2 ,[loop will start from 2 and end on 2 not including it which is not feasible] so program will work normally it will print prime as (null % i != 0)
@@manpreetsinghpanesar5748 so if the loop will work, then why won't the first condition be checked or run? Why only the else part will work?
your python series are great sir ,thanks for this
Thank you
Finally, a clear, concise, easily understood explanation for finding prime. Thanx.
one of the Best star teacher on TH-cam hats off to you sir
def prime(num) ->bool:
if num == 1:
return False
elif num == 2:
return True
else:
ran = int(num ** 0.5)
for i in range(2,ran+1):
if num%i != 0:
return True
x= int(input("Enter Number: "))
n = prime(x)
if n:
print("Prime")
else:
print("Not Prime")
n=int(input("Enter a number"))
c=0
for i in range(1,n+1):
if n%i==0:
c+=1
if c==2:
print("prime")
else:
print("Not prime")
Bro the tutorial itself is wrong, your code works perfectly thank you!
Yeah he made a mistake for i in range (1,num+1) should come and the +1 is excluded and it prints 1:num)
x=int(input("input your number
"))
for i in range(2,int(x/2+1)):
if(x%i==0):
print("enter number not prime number")
break;
else:
print("enter number is a prime numbere
")
print("SIR YOU RELAY HELP US SO MUCH SO THANK YOU SOOOOOOOOOOOMUCH FOR YOUR EFFORT")
Super
But it better x//2insted of x/2
You also right. That's why I caste here by int.
Please explain me this part int(x/2+1)
@@marjugasvoiceout3547 let x=3 then x/2=1.5 now 1.5+1=2.5 now int(2.5)=2 for the casting float value become int value.
My Prime code, for checking prime number there is no need to run the loop till its number. We an even achieve it by running the loop till (num/2)+1. In this way you can reduce half of the effort. Will be useful while checking for large numbers.
Code :
num = int(input("check number is prime or not :"))
for i in range(2,int(num/2)+1):
if num % i == 0:
print("not prime")
break
else:
print("prime")
You dont have the need to add 1.
Wouldn't need the second "int" call in the range function. But you probably already know that now :D
@@jatinlekhwar6798 I think you do, if you don't put 1 then it will return 4 as a prime because the range will be (2,2) and it will go into else, correct me if I am wrong
@@MikoKikoJo what do you mean, it will throw an error
@@MikoKikoJo you have to, if you put any number like 5 in that formula, answer will be 3.5 and range cannot go till 3.5 it needs integer.
Sir in this case if we give num=1
Then output is prime
But 1 is not a prime
Great Mr Naveen,this is the real trick if you want to be a good programmer..Good job,,,keep doing this,People need to learn.
num = int(input("Enter any number "))
if num>1:
for i in range(2,num):
if num%i==0:
print("Not a prime number.")
break
else:
print('it is a prime number')
else:
print('not a prime number')
Why you wrote else conditions two times?
@@akbarmohammad5081 One is for "if-else" statement and another is for "For-else" But their is no need for "If-else" if u want you can include
Could you say why you use break, I'm not under stand by from video
dheeraj kumar, because we don’t have to continue dividing ‘num’ by ‘i’. ‘break’ stops ‘for’. For example, ‘num’ = 10, and if 10 % 2 = 0 then this number is definitely not a prime number because prime number can only be divided by itself and by 1, and we don’t have to continue dividing ‘num’ by 3, 4 and so on. Do you understand it now?
num=int(input('enter the number'))
if num%2==0 or num%3==0 or num%5==0 or num%7==0 and num%num!=0:
print('not prime')
else:
print('prime')
try this mam
Your beginner video's are best in TH-cam sir, in this lockdown wanted to be productive and thought of learning python after a lot of playlists and channels your channel has got all the information and tutorial a beginner needs
Using while loop for primes
n = int(input('Enter a number'))
i = 2
while (i
if you want to try with function:
def prime(num):
for i in range(2,num):
if num % i == 0:
return "not a prime number"
else:
return "prime number"
num = int(input("enter a number: "))
print(prime(num))
Hey , do you know how to do this ques?
Consider a tuple T1 = (1, 2, 5, 7, 9, 3, 4, 6, 8, 10). Write a function primes() that accepts tuple T1 as argument and creates a list T2 having values that are prime numbers in the tuple T1. The function should return a dictionary primeCubes where keys are items of the list T2 and the values are cubes of the keys. For example, when T1 as passed as an argument, T2 will be [2, 5, 7, 3] and primeCubes will be {2:8,5:125,7:343,3:27}.
import math as m
x=int(input("Enter The Number :"))
b=m.floor(m.sqrt(x))
for a in range(2,b+1):
if a**x%x==a%x:
print("The no. is prime")
break
else:
print("Not prime")
Thank You sir for your great lectures..
to my knowledge this is efficient:)
x=int(input("enter a vlaue"))
for i in range(2,x):
if x%i==0:
print("not a prime")
break
else:
print("is a prime")
It's workg🥰 tq
Little more optimized..
import math
num = int(input("Enter the number:"))
n = math.floor(math.sqrt(num))
for i in range(2,n + 1,1):
if num % i == 0:
print("The number is not prime, divisible by", i)
break
else:
print("The number is prime")
@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????
you can add special condition for 2 because its a start from 2
bro when you debug this, range function doesn't allow it to read ' if ' statement it straight away jump to 'else ' statement.
num=int(input('enter the number'))
if num%2==0 or num%3==0 or num%5==0 or num%7==0 and num%num!=0:
print('not prime')
else:
print('prime')
try this
a = int(input("Enter a number: "))
if a
We wants such type of videos from you dear navin sir
count = 0
n = int(input("Enter a number:"))
for i in range(1, n+1):
if n % i == 0:
count +=1
if count == 2:
print(n, "is a Prime number")
else:
print(n, "is Not a Prime number")
num = int(input("Enter the num:")) # taking input
if num < 2:
print("Not prime")
else:
for i in range(2, num): # iterate over possible divisors
if num % i == 0:
print("Not Prime")
break # if a divisor is found, no need to continue checking
else:
print("prime")
Guys this will also work for 0 and 1 and also for negative numbers.
Tnx bro
n=int(input("enter the number:"))
c=0
for i in range(1,n+1):
if(n%i==0):
c+=1
if(c==2):
print(" prime")
else:
print("not prime")
x=int(input("Enter any interger number: "))
for i in range(2,x):
if x%i==0:
print("=> it is not a prime")
break
else:
print("=> it is a prime")
Hritwik Haldar it is same bro .... not efficient
bto agr input 1 ho toh kaise kroge ??
n=int(input("enter the value of n"))
if(n==1):
print("it is not prime number")
for i in range(2,n-1):
if(n%i==0):
print("it is not a prime number")
break
else:
print("it is a prime number")
at first i used to hate for loop and while loop and after watching your and seeing the examples i used to love them sir thanks a lot❤️btw i am aman raj😀
a = int(input("Enter the number = "))
count = 0
if (a>0) :
if (a == 1) :
print("{} is neither a prime nor a composite number.".format(a))
i = 1
while (i 2) :
print("{} is a composite number.".format(a))
elif (a
♐To get code in an efficient way - just reduce the no. of iterations by half😉
code:
num = 25
for i in range(2,(num//2)):
if num%i==0:
print("Not Prime")
break
else:
print("Prime")
o/p:
not prime
you can make to square root it is more efficient than halfing number
use seive algo
@@adithyaramapuram4995 brother, you'll have to add 1 after taking the square root. if you directly put sqrt value in range, it won't get included in the code and henceforth resulting in wrong output.
from math import sqrt
n = 5
for i in range(2, int(sqrt(n) + 1)):
if n % i == 0:
print(n, "is not a prime number")
break
else:
print(n, "is a prime number")
I have written below code. I am implementing things after learning from your course. Thank you Sir.
nums=range(1,10)
for num in nums:
for i in range(2,num):
if num%i==0:
print(num,"Not prime number")
break
else:
print(num,"Prime number")
x= int(input('number=?'))
If x==1:
print('neither prime nor composite')
Elif x==2:
print('prime')
Else:
For i in range(2,x):
If x%i==0:
print('not prime')
Break
Else:
print('prime')
Break
Print('bye')
The last line is an error print() p is small😂
@@anirudh4671 Huh acting as friendly Console showing error😹
x=int(input("enter an number howle"))
if x%2==0 :
print(x,"not prime")
elif x%3==0 or x%5==0:
print(x,"not prime")
else:
print(x,"prime")
I like the input part 🤣🤣
input is 49 output is prime 💀
but I thought 49 is non prime bro
we can improve the time by only checking odd divisor till the square root of the given num.
for eg - num is 29 then check num check by it by 3,5 ,7.
No..143...has divisor 13.
n=int(input("enter a number"))
for i in range(2,int(n/2)):
if(n%i==0):
print("not prime")
break
else:
print("prime")
For this program
x=int(input("Enter a number"))
count=0
for i in range(1,x):
if x%i==0:
count=count+1
if(count>2):
print("The number is not prime")
else:
print("The number is prime")
Sorry,but it is wrong
Yes Its Wrong
n = int(input("Enter a number :"))
i=2
while i
Hey the value i should increase till that no.
from math import *
x = int(input("Enter the number: "))
for i in range(2,floor(sqrt(x))+1):
if x%i==0:
print("Composite")
break;
else:
print("Prime")
Instead of floor use ceil and don't add it
Correct
@@BeUniqueMotivation yeah thank you
All these days i was thinking who in the world invented this programming ?......but after watching ur videos i really feel learning programming is fun!!!
Your tutorials makes coding life much more simple :)
import math
for i in range(2,101):
count=0
for j in range(2,int(math.sqrt(i))+1):
if i%j==0:
count=count+1
if count==0:
print(i)
Your Python series are Great sir, Thank you so much for this ..😇
Sir i tried my best to find the time efficient manner to solve this problem 😉
Please take a look on it and give some suggestions if any..
Code:
from math import sqrt
n = int( input ( 'Enter a number :') )
if n==0 or n==1 :
print( 'Not Prime' )
elif n==2 :
print( 'Prime' )
elif n%2 ==0 :
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' )
why you increasing the value of i by 2 everytime, why not 1?
@@mananagarwal1212
I did the correction as I didn't used editor i forgot one step..
Explanation of Code:
Firstly it will check that the number is divisible by 2 or not if not then it will again check from 3,5,7,9.... till ✓n
@@rishisetpal3537 okay thanks
Its not efficient bro, why are u making it complex . Let it be simple
@@dishantkumbhar8822 i did not understand.. like how.?
Can you try to explain with the help of code.?
num = int(input())
for i in range(2,num):
if num%i==0:
print("not prime")
break
else:
print("prime")
sir this is my efficiently modified by the clue you have given 👇👇
num = 19
for i in range (2,int(num/2)):
if num % i == 0:
print("not prime")
break
else:
print("prime")
n=int(input())
for i in range(2,n//2):
if n%i==0:
print(n,"is not prime")
break
else:
if n
num=int(input("number"))
for i in range(2,num):
if num%i==0:
print("not prime")
break
else:
print("prime")
better code
Your code is same as sir explained in the video you just took input from user bro. Sir meant another method of code which involve less step.
a=int(input("enter a number"))
count=0
i=1
while i
a=int(input("enter a number"))
count=0
i=2
while i
lower=int(input("Enter lower limit"))
upper=int(input("Enter upper limit"))
for num in range(lower, upper+1):
for i in range(2,num):
if num%i==0:
break
else:
print(num)
So ur problem is.....?
Import 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")
It doesn't work for number 4
i=2
while(i
What is x
Num =int(input("enter a No."))
For i in range(2,num):
If num%i==0:
Print("not prime")
Break
else:
Print("prime")
I did same but not working well
@@pranshupandey5907 It is because, In first line "Num" is in Cap letter Try to make as same for all "num"
Just printing the num which we enter
Just add one code between 1st nd 2nd line that is -if num>1:
What if i enter 2 because it's a prime number
from math import sqrt, floor
num = int(input("Give me a number.."))
if num == 1:
print("Not a prime")
quit()
else:
if num == 2:
print("Prime")
quit()
if num > 2 and num % 2 == 0:
print("Not a Prime Number.")
else:
e = 1 + floor(sqrt(num))
for i in range(3, e, 2):
if num % i == 0:
print("Not a Prime Number...")
break
else:
print("Prime Number")
This is a code which prints all prime numbers from 1 to 50
for num in range(1,50):
for i in range(2,num):
if num%i==0:
break
else:
print(num)
2 print nhi hoga
what if we want to just print the NON prime numbers?
for i in range(1, 20):
if i % 2 != 0:
print(i) This is efficient and I want to say you are a great teacher I actually learned everything i know from you. Which is only python and JavaScript but still I will learn more from you.
Wrong
@@uttkarsh7823 its actually right it worked for me. what did you see wrong. it would be nice if you pointed it out.
That’s for even ni buddy
for i in range(2, num//2):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
For input 4 it is showing as 4 is prime number but 4 is not prime (factors are 1,2,4)
U should add 1 in range
range(2,(num//2)+1):
Then 4 will be a "not prime"....
@Prem Kumar It works....
For n=2 it directly enters the else part and it becomes a prime number
@Prem Kumar bro here we have to use "for-else" not "if-else"
Then n=2 enters the else part
@Prem Kumar No bro "if loop" will not execute bcoz
In range(2,(2//2)+1) is range(2,2) i.e it doesn't enter "if loop"
A code for printing Prime no.s
for I in range(1, 101) :
if i%2 ! =0:
print(I)
Done!!!
n=int(input("Enter a number to check : "))
for i in range(2,int(n**0.5)+1):
if n%i==0:
print("Not Prime")
break
else:
print("Prime")
Explain that exponent please
@@venugopal-kh5zc in python "**" is used for exponential.
Eg. 5^2 is written as 5**2
@@newsinfo27 that is I now sir ...I want why using exponent. What is logic here
Explain once
@@venugopal-kh5zc ohh sorry.
If a given number n is not divisible by any number from 2 to root(n) then it's prime.
isprime=int(input())
for i in range(2,int(isprime/2)):
if isprime%i==0:
print("not prime")
break
else:
print("Prime")
range(2,i nt(isprime/2)) --> if the input is 4 then range(2, 4/2) --> range(2, 2) --> then else statement will directly executed and print prime
for n in range(100):
Count=0
for i in range(1,n+1):
if(n/i==0):
count+=1
if count==2:
print(n)
There is no need to iterate the for loop upto n-1 just iterate it upto n/2
Cause a number having a value more than half cannot divide that number
Then the time complexity will reduce to n/2 time which is n-1 times in your code
Actually iterating upto floor(n**0.5) is even more efficient
@@khamza8926 hi khamza, can you explain your point of view
@@anwarsheik3329search for sieve of eratosthenes proof
this is the best beginner videos on TH-cam
I know this is a long code, but I think it will be easier to process.
a = int(input("type here-"))
b = [2, 3, 5, 7]
for i in b:
if a ==i:
print("prime")
elif a%i==0 or a==1:
print("not prime")
break
else:
print("prime")
Bro how about 121 Or 169?
this is a hardcode method
it prints prime 2 times
display the prime numbers within a range
x = int (input ("enter your number ? "))
y = int (input ("enter your number ? "))
for i in range (x,y):
for j in range(2,i):
if i%j==0:
break
else:
print (i)
a = [ ]
for x in range (2,50):
isPrime = True
for num in range(2, x):
if x % num == 0:
isPrime = False
break
if isPrime:
a.append(x)
print(a)
thnx
n = int(input("Enter a number"))
n1 = int(n / 2)
for i in range(2, n1):
x = n % i
if (x == 0):
print("Not a prime no")
break
else:
print("Prime no")
sir this code won't work for num=2. Since although 2 is divisible by 2 it is a prime number
it works
big brain
@@onkarparandwal2386 how it works?
2 is the even prime number.
2 is a prime number
num=3
factors=[]
for i in range(1,num+1):
if num%i==0:
factors.append(i)
if len(factors)>2:
print("not a prime")
else:
print("prime number")
perfect channel..........!!!!!!!!!!!!!!
I was totally confused with for loop and while loop, i mean didn't know to use it well..after seeing some of ur vids i was happy....and got some idea abt python language....i will see all ur python vids as it's too interesting..
btw my doubt was what is the code to print all prime numbers from 0 to 100...?
num = int(input("Enter the number: "))
factors = []
for x in range(1, num+1):
if num % x == 0:
factors.append(x)
# A prime number is a number which has only 2 factors one itself and second 1
# print(len(factors))
if len(factors) == 2:
print(f"Congratulations {num} is a prime number, with factors only {factors}")
else:
print(f"Aaah! sorry {num} is not a prime number because it has factors {factors}")
This one is correct. Me also do like same as you.😎
my efficient way in this code user can choose its own number
x=int(input('enter a number'))
for i in range (2,x,1):
if x%i==0:
print ('not prime')
break
else:
print (' prime')
Sir, the program you wrote is not valid if the given number is 2. Since we are starting from 2, the given number(2) will be divisible and the program will give the output as Not Prime whereas 2 is a Prime number. Any other way around this?
a=int(input("enter a number "))
if a==2:
print("prime")
for i in range(2,a):
if a%i==0:
print("not prime")
break
else:
print("prime")
break
from math import sqrt
n = int(input("Enter the number"))
if n2 and n%2==0:
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")
while True:
n = int(input("Please enter minimum Range"))
m = int(input("Please enter maximum Range"))
d = int(input("please enter range difference"))
x = range(n, m, d)
s = False
for i in x:
if i > 2:
for j in range(2, i):
if i % j == 0:
break
else:
print(i)
c = int(input("1 for continue 0 to end"))
if c == 0:
break
Thank you. A very useful video. Could you please add this video in python video list so We can reach them easily.
This 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
Hi can you tell me if the -------> 'else' at the bottom is with 'while true' indentation or with 'while b
@@sumeetrox2479 oustide whileb
print a prime number, greater than or equal to a given number
Your python series and other technical videos are excellent sir thank you sir it's help me a lot
'x=int(input("enter the number "))'
for x in range(3,500):
mod=2
kalan=x%mod
if(kalan==0):
'print(x,"not prime")'
while kalan!=0:
while mod
It's seems,, there is syntax error, seems after running this code ,it will not be executed
a=int(input('Enter number:'))
check = False
for i in range (2,a):
if a%i == 0:
print('its not a prime number')
check = True
break
if check == False:
print('Its a prime number')
I think it takes more complexity
num=int(input("enter the number"))
for i in range(2,num):
if num%i==0:
print("it's not a prime no.")
print("because it's divisible by",num//i,'and',num,'itself')
break
else:
("it,s a prime number")
The other better way is to check if number is divisible by 2 first and then only check for odd numbers upto square root of the number.
n=int(input("enter the number you want to check: "))
for i in range(2,n//2):
if n%i==0:
print('its not prime')
break
else:
print("its prime")
i m learning now brother.
@@raghavendraam719i did not understand at all😢
sir,
itsead of giving number inside code
we can write
a = int(input(enter a number))
for i in range(2,a):
if a %i==0:
print("its not a prime number")
break
else:
print("its a prime number")
print("i love telusko")
out put (1) :---- output (2) :-----
enter a number 11 | enter a number 12
|
its a prime number | its not a prime number
|
i love telusko | i love telusko
a=int(input("enter a number"))
count=0
for i in range(1,a,1):
if a%i==0:
count+=1
if count==1:
print("prime")
else:
print("not a prime")
p = 33
count = 1
for i in range(2, p // 2):
if p%i == 0:
print('Not Prime')
break
count = count + 1
print('Count = ', count)
else:
print('Prime')
Great great to see you back on Python series. Lovely. Thanks Navin.
a number can be divisible by itself and 1 for sure but except these it can only be divisible by the numbers ranging from 2 to upto half of that given number. so instead of checking from 2 to n we can check from 2 to n/2.
def findPrime():
num = int(input("Enter a number : "))
if num == 1:
return print("Not a Prime number")
for x in range(2, (num // 2) + 1):
if num % x == 0:
print("Not a Prime number")
break
else:
print(f"{num} is a prime number")
findPrime()
a=int(input("enter number to check: "))
check=True
for i in range(2,int((a/2))) :
if a%i==0 :
check=False
break
else :
check=True
if check==True :
print("prime")
else :
print("not")
What about 1 I think it will show prime
num = int(input("Enter a number:"))
for i in range(1, num):
if num / i == i:
print("Square of", i)
break
else:
print("square root donot exist")
a = input("Which number do you want to figure out if Prime or not? ")
a = int(a)
b = a//2
for j in range (2,b):
if a % j == 0:
print(a, " is not a Prime Number")
break
else:
print(a, " is a Prime Number")
U can do it in the fst line itself int(input("enter a number ")) ..no need to do a = int
trying efficient way...it is right sir?...
def prime(num1):
if num1 ==1 or num1==0:
return False
for i in range(3,num1, 2):
if num1%i==0 or num1%2==0:
return False
else:
return True
n=29
for x in range(2,n):
if n%x==0:
print("Not prime")
break
else:
print("prime")
Range (0,n) ya fir range (1,n) s 2 ka b problem solve ho jayega
to print the list of prime numbers from 1 to given number
n=int(input('enter the number'))
list= [ ]
for i in range (1,n+1):
count=0
for j in range(1,i+1):
if i%j==0:
count+=1
if count==2:
list=list+[i]
print('the prime numbers are ',list)
num=int(input("enter the number"))
for i in range(2,int(pow(num,0.5))):
if num%i==0:
print(num,"is not prime")
break
else:
print(num,"is prime")
Enter 4,.. it shows prime
Why did you take pow() function in this?
Here,We can use sqrt() instead pow()
He use pow() to find its sqrt value.
the most simplest code sir
#program to check the no. is prime
n=int(input("enter the no.: "))
for i in range(1,n+1):
if n%1==0 and n%i==0:
print("the no. is prime")
break
else:
print("the no. is not prime")
but what if num=2? how will range(2,2) generate a dataset? will it be blank?
Create an Elif condition,
elif num == 2:
print(“2 is a prime number”)
@@falakchudasama9746
And for
I had the same dobut but when I runed the cmnd with input as 2 it printed number is prime
Because 2 is not prime number 😂
Stupid 2 is even prime@@narendrachampaneri8112
by using while condition
n=7
i=1
c=0
while i
Continuously uploading videos thats a great sign sir
we can further cut the range of factors by excluding even numbers as factors of odd numbers
num = int(input('enter any number'))
factors_range = range(3, int(num / 2)+1, 2) if num % 2 != 0 else range(2, int(num / 2)+1, 1)
for i in factors_range:
if num % i == 0:
print('number', num, 'is not a prime number, divisible by', i)
break
else:
print('it is a prime number')
You're the best teacher soo far!
Please how can i found your Java tutorial?
go to playlist.
for i in range(1,101):
for j in range(2,i):
if i%j==0:
break
else:
print(i)
Plz make a video on Selenium with python and welenium with python🙏🙏plzz ,at least in between the lockdown we learn something new