mam please say how this technique applies if we give input number 2 ??? for other numbers i understood this code perfectly except number 2 case please reply mam
When input is 2, for loop body will not execute and else part will execute :) In for loop start is 2 and end is 2 so it won’t execute loop body :) And because for loop is not terminated by break statement , else par will execute :)
There is not need to check the for divisors greater than sqrt(num). You can increase the efficiency of this program quite a bit by changing the for loop to: for i in range(2, sqrt(num))
@@okechukwuerinne2039 number=2 divisor=2 if number ==divisor or number==1: print("prime number") else: if number%divisor==0: print("Not prine") else: print("Prime") This is code for short range. But when it comes to find prime number in some range then this code is wrong.
this code is wrong input numbers like 27,321,etc... which are not divisible by 2 but are not prime numbers.... still the programme gives the numbers to be prime correct programme code num=int(input('Enter a positive number :')) if num > 1: # Iterate from 2 to n / 2 for i in range(2, int(num/2)+1): # If num is divisible by any number between # 2 and n / 2, it is not prime if (num % i) == 0: print(num, "is not a prime number") break else: print(num, "is a prime number") elif num==0: print(num,'is neither prime nor composite.....') else: print(num, "is not a prime number")
We can use else case with loops also. Here we want else part with for loop. The else block just after for/while is executed only when the loop is NOT terminated by a break statement.
num = int(input(":")) if num > 1: i = 2 while i < num: if (num % i) == 0: print(num,"is not a prime number") break i =i+1 else: print(num,"is a prime number") else: print(num,"is not a prime number") :)
lower=int(input("lower no ")) upper=int(input("upper no ")) i = 2 for num in range (upper,lower+1): while i < num: if (num % i) == 0: print(num,"is not a prime number") break i =i+1 else: print(num,"is a prime number") i want to print prime no's in the intervals like this, without two for loops ..
lower=int(input("lower no ")) upper=int(input("upper no ")) for num in range (lower,upper+1): i=2 while i < num: if (num % i) == 0: #print(num) print(num,"is not a prime number") break i =i+1 else: print(num,"is a prime number") Try this :)
@@AmulsAcademy thank u very much mam . I've identified my mistake 🙏 u dont believe me , i have been fighting with this prime no's prg for past TEN days and I've found ur videos accidentally and i havnt expected this much response from u . u r really a respectful and a responsible teacher .🙏
The else block just after for/while is executed only when the loop is NOT terminated by a break statement. So you need to break statement here. Note: remove break and try to execute the program.
Madam I following your classes daily I am big fan of u yesterday I attended one interview I passed written test In second round they conducted system test But they gave to me a difficult task That task name is FLAMES I HOPE YOU KNOW THAT FLAMES CONCEPT before he conduct the system test He explained to me that FLAMES Take two persons name Cancel that common letters Count the remaining Letters For example total remaining letters are:(5) How to get this out put By using ptython code Plz explain this out madam
Try this: str1 = input("name1:") str2 = input("name2:") for i in str1: for j in str2: if i==j: str1=str1.replace(i,"",1) str2=str2.replace(i,"",1) print(i,j) print(str1,str2) print("remaining characters in str1:",len(str1)) print("remaining characters in str2:",len(str2)) :)
in the for loop we took range from 0 to num when num=2 range becomes 2 to 2 range(2,2) so it won't execute for loop body :) You can execute this and check for i in range(2,2): print("hello") else: print("hi")
Even or Odd and Prime or Composite numbers are different programming logics. What you are trying to imply in here is that every number divisible by 2 is not a Prime number when 9, 15, 21 and so on are not Prime numbers and are not divisible by 2. This is unclear and confusing. The way the tutorial is being discussed has never changed and is still the same as other content creators stating they found the answer behind Prime number logics.
you are the only one in the comment whom i found have some knowledge, other than people here are saying they are clear , its just a soln for even no. not for prime no.
please help i am getting 55 as prime number. by writing below code. num= int(input("enter any number")) for i in range(2, num): if (num % i) == 0: print (num,' number is not prime') break else: print (num,' number is prime') break
num= int(input("enter any number")) for i in range(2, num): if (num % i) == 0: print (num,' number is not prime') break else: print (num,' number is prime') Now check whether it will give correct output or not :)
num = int(input("enter number to check prime number : .. ")) for i in range(2,num): if (num % i ) == 0: print (num,"not prime") break else: print(num,"number is prime")
Hi! Can you please make a video on the question: If a list in python has mix of strings & numbers, how will you make separate lists of strings & numbers? I saw ord() for getting ASCII code in python & chr() for converting ASCII codes to characters somewhere & tried to use them to get answer of this question but it did not work!! :(
wrong concept .plz correct it acc to uyou when i will take 21 as ainput it will show it is prime no. as 21%2==1 but 21 is not a prime nno. ur soln is for even no.
you won't get proper output:) When we get divisor of given number then we know that number is not prime so we need to come out of the loop that's why we used break :)
@@AmulsAcademy please make video on python interview programming question.. But not mcq... Something like paragraph narrated question.... Need it because I am final year student.. Please
As per your code, I given 111 and 333 then it is showing both prime and not prime, don't know why it is showing like that. CODE: #For checking prime number num = int(input("Enter the number:")) if num>1: for i in range(2,num): if (num%i)==0: print(num, "it is not a prime number") break else: print(num, "It is prime number")
else is for, for loop not for if condition. num = int(input("Enter the number:")) if num>1: for i in range(2,num): if (num%i)==0: print(num, "it is not a prime number") break else: print(num, "It is prime number") :)
Simple and good .need more videos on the programs which are general in interviews
Sure:)
Thank you:)
Yeah, yeah ,yeah😂😂😂
Thank you so much for explaining with example. I was confused with for loop. Now ,it is completely clear to me ....how it works.
Glad it was helpful! :)
after watching so mny videos i understood from yours ty:-):-)
Glad to hear that :)
how you understood tell me also its totally wrong code ,it is for even no. when you will do it for 21 it will show prime but 21 is not prime....
your voice and explanation both are amazing
Thank you 😊
Hi . Very well explained . Easy to understand and solve it
Thank You
Welcome:)
Thanku so much .. it really helped me...❤️
Glad to hear that :)
Thank you so much! But, what do we do with the input 2 in the end?
2 is a prime number :)
Bro same doubt , did you get the answer
Well done.. Perfectly explained
Thank you :)
Ur voice keeps entertaining..!
Very good video you solve me very very big problem thank you very much again
Your teching ideas mind blowing
mam please say how this technique applies if we give input number 2 ??? for other numbers i understood this code perfectly except number 2 case please reply mam
When input is 2, for loop body will not execute and else part will execute :)
In for loop start is 2 and end is 2 so it won’t execute loop body :)
And because for loop is not terminated by break statement , else par will execute :)
@@AmulsAcademy ok mam i got it thanks for the reply
There is not need to check the for divisors greater than sqrt(num). You can increase the efficiency of this program quite a bit by changing the for loop to:
for i in range(2, sqrt(num))
Wish I would of found this video a couple hours ago. Had to settle with the brute force method for my assignment.
Excellent Explanations...👍👍👍
thank you mam!!!....ur vedios make me to solve programs on my own :)
You don't need to check all the way till num, running the loop till num//2 would get you the same result.
yes. However there is still a shorter range than n/2.
I tried this and got a wrong output. I got "4 is a prime number." Perhaps I messed up the program somewhere.
@@okechukwuerinne2039
number=2
divisor=2
if number ==divisor or number==1:
print("prime number")
else:
if number%divisor==0:
print("Not prine")
else:
print("Prime")
This is code for short range.
But when it comes to find prime number in some range then this code is wrong.
@@okechukwuerinne2039 for such basic exceptions, you should have already added another if statement.
if num%2==0 then print False
thank you for this keep up the good work
Thank you 😊❤️
Good explanation with impressive voice.....
Want to listen more of your voice:)
Thank you :)
I like your explanation 👌👌 TQ so much
you explained it very Well
Thank you :)
no she explained wrong go for 21,9
this code is wrong input numbers like 27,321,etc...
which are not divisible by 2 but are not prime numbers....
still the programme gives the numbers to be prime
correct programme code
num=int(input('Enter a positive number :'))
if num > 1:
# Iterate from 2 to n / 2
for i in range(2, int(num/2)+1):
# If num is divisible by any number between
# 2 and n / 2, it is not prime
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
elif num==0:
print(num,'is neither prime nor composite.....')
else:
print(num, "is not a prime number")
@@A4KSHAT Bro is 27 a prime number???
ofcourse not , so how it is showing that it is a prime number
@@SanOp-zx1pc i am sorry it is show it is not a prime number
Thank you so much for this; it was a life saver.
🤣🤣🤣🤣
U voice is good....
Super explaination on the whole youtube
Great explanation thanks
Thank you :)
Can you explain why number=2 shows up as prime in the code when 2÷2=0? I know 2 is prime
Check for loop range 😊
Video is good
#TECH_INTERVIEW_PREPRATION
Thank you 😊
🙏🙏🙏
Mam why else is straight under for loop it should be under if know mam plse do reply mam
We can use else case with loops also.
Here we want else part with for loop.
The else block just after for/while is executed only when the loop is NOT terminated by a break statement.
Sisy.. plz put videos for sum of next 2 consecutive numbers
Will try 😊
How to save it with which name
It's very good 👏👏👍
I am watching this masterpiece in Dec 2021
mam why you have used else with for loop but not with if
else case can be used with loops also :)
here we need else part with for loop :)
hi mam,
pl write this example with while loop .
i hav tried many times but always stuck wit where to give the increment "i=i+1" operator .
num = int(input(":"))
if num > 1:
i = 2
while i < num:
if (num % i) == 0:
print(num,"is not a prime number")
break
i =i+1
else:
print(num,"is a prime number")
else:
print(num,"is not a prime number")
:)
@@AmulsAcademy thank u very much .
can u pl tel me wats wrong in this code n if possible could u correct it ?
lower=int(input("lower no "))
upper=int(input("upper no "))
i = 2
for num in range (upper,lower+1):
while i < num:
if (num % i) == 0:
print(num,"is not a prime number")
break
i =i+1
else:
print(num,"is a prime number")
i want to print prime no's in the intervals like this, without two for loops ..
lower=int(input("lower no "))
upper=int(input("upper no "))
for num in range (lower,upper+1):
i=2
while i < num:
if (num % i) == 0:
#print(num)
print(num,"is not a prime number")
break
i =i+1
else:
print(num,"is a prime number")
Try this :)
@@AmulsAcademy thank u very much mam . I've identified my mistake 🙏
u dont believe me , i have been fighting with this prime no's prg for past TEN days and I've found ur videos accidentally and i havnt expected this much response from u .
u r really a respectful and a responsible teacher .🙏
Nicely explained, but if i enter number as 2, the code does not execute. please help
Thank you :)
No it will work properly for input 2.
@@AmulsAcademy thank you. noticed indentation was not properly placed in my code
Yes indentation matters a lot in python :)
Mam why did u use break. Can u tell me the use of it please 🙏🙏
if you want to exit from the loop then you can use break inside the loop.
Execute the program without break you can see the difference :)
@@AmulsAcademy oo ok mam thanks
maam but if we put 9 it is showing that it is a prime number but as we know that it is not a prime number.....maam how to solve this problem?/
Give me the program 😊
You wrote print(num,"is not a prime number" ) in FOR loop why it is not printing for num number of times
my teacher I think we don't need the break statement
so that after the if condition becomes false the for else will work
The else block just after for/while is executed only when the loop is NOT terminated by a break statement.
So you need to break statement here.
Note: remove break and try to execute the program.
@@AmulsAcademy right
Thank you so much for this
My Pleasure :)
wow..
thank you very much.
You are most welcome :)
mam do you teach in valia ?
Madam I following your classes daily I am big fan of u
yesterday I attended one interview
I passed written test
In second round they conducted system test
But they gave to me a difficult task
That task name is FLAMES
I HOPE YOU KNOW THAT FLAMES CONCEPT
before he conduct the system test
He explained to me that FLAMES
Take two persons name
Cancel that common letters
Count the remaining
Letters
For example total remaining letters are:(5)
How to get this out put
By using ptython code
Plz explain this out madam
Try this:
str1 = input("name1:")
str2 = input("name2:")
for i in str1:
for j in str2:
if i==j:
str1=str1.replace(i,"",1)
str2=str2.replace(i,"",1)
print(i,j)
print(str1,str2)
print("remaining characters in str1:",len(str1))
print("remaining characters in str2:",len(str2))
:)
how about if we want to check the list of prime numbers in a range x to y, where x and y could be any range..
I did make a video on how to print prime numbers in particular range please check that :)
@@AmulsAcademy Yes watched it. It makes a good logic. Please come up with more videos like these :)
Too good ❤
Here i got stuck with case number =2 here 2 modulo 2 will be 0 still it prints 2 is a prime number how does that work
in the for loop we took range from 0 to num
when num=2
range becomes 2 to 2
range(2,2)
so it won't execute for loop body :)
You can execute this and check
for i in range(2,2):
print("hello")
else:
print("hi")
Amulya's Academy thank you so much for the explanation!! Got it
a=int(input("enter:"))
if (a%2==0) or (a%3==0):
print("it is not prime number")
else:
print("it is prime")
this is write or wrong
hey 2 is a prime no but 2%2==0 then how does this work
Please check for loop range, starting value and end value is same that is 2, so it won’t execute loop body 😊
@@AmulsAcademy no it's not same it becomes(2,1) right as end value is excluded
Mam, why are u using for loop for all program?
If you want you can use while loop also.
:)
may i give u a suggestion
pls run the programme and show us the output
it will ensure that ur codes are correct
Thank you for the suggestion:)
Didn't i show the output in this video?
Usually i do execute my program.
:)
Arya V S Watch the video properly she has shown the execution
by writing your code, for number 2 it is not showing anything..please help me
No it will print 2 is prime number.
Give me the program i will check for you :)
Thanks:) it's working...👍😊
Nice mam..
Thank you :)
Mam this code is not working for number 2.
how to check the number is a prime number in a range entered by the user????
Give me an example :)
@@AmulsAcademy for example...user enters the starting range and ending range...from that range we have to find which numbers are prime numbers.
Even or Odd and Prime or Composite numbers are different programming logics. What you are trying to imply in here is that every number divisible by 2 is not a Prime number when 9, 15, 21 and so on are not Prime numbers and are not divisible by 2. This is unclear and confusing. The way the tutorial is being discussed has never changed and is still the same as other content creators stating they found the answer behind Prime number logics.
you are the only one in the comment whom i found have some knowledge, other than people here are saying they are clear , its just a soln for even no. not for prime no.
I was also confused that by using this method it will print prime statements even for odd numbers..
Are u from tamil nadu ?
i understood well thanks for the video
No I am from Karnataka.
Thank you :)
@@AmulsAcademy i am from kerala, i can easly recognise south indains
Hello :)
@@AmulsAcademy hello
you are nice teacher
Hello dear we have to find out a prime number or not means there is three conditions can you please explain those three conditions
Mam how can we print those prime numbers
please help
i am getting 55 as prime number.
by writing below code.
num= int(input("enter any number"))
for i in range(2, num):
if (num % i) == 0:
print (num,' number is not prime')
break
else:
print (num,' number is prime')
break
num= int(input("enter any number"))
for i in range(2, num):
if (num % i) == 0:
print (num,' number is not prime')
break
else:
print (num,' number is prime')
Now check whether it will give correct output or not :)
num = int(input("enter number to check prime number : .. "))
for i in range(2,num):
if (num % i ) == 0:
print (num,"not prime")
break
else:
print(num,"number is prime")
why else is used for for loop not for if
We can use else case with loops :)
Thank you
Pleasure :)
withought using breal ,how to solve it
Mam...it is not working for *21* . What to do? But thanks for the video mam
21 is not prime number right ? What is the problem ? :)
Mam....When I entered 21, then it checks and says that *21 is prime* . Then I again tried designing a new code for it. Thanks for your reply mam😄
How I write this code in list comprehension method
% k bd wala else iff k indention m aan chahiy th na jo for k nicje ku aara
Thank u didi ❣️❣️🙏🙏
Most welcome 😊
nice one.
How to do this without using break ?
Mam if we check no 2 how it will work?
I was wondering the same thing.
amazing ...
Thank you :)
Ur range function is not working may I know the reason
How to get a preceding number of a given number
input-1 :)
Thank you❤
can't we add int in the input statement ?🤔🤔🤔🤔🤔🤔
How to do same program with while loop
Please explain Circular prime number in python mam
Nice vid
Thank you :)
then why the hell my program says 9 and 15 are prime number when i write the same program as yours.
According to your code,it starts dividing by 2.
So,2%2==0
Then according to your code,2 should not be a prime number
No because in the for loop range will become 2 to 2 at that time .
so it won't execute for loop directly goes to else part
:)
Amuls Academy Thanks.
@@AmulsAcademy Did not understood range become 2 to 2 at that time
Hi! Can you please make a video on the question: If a list in python has mix of strings & numbers, how will you make separate lists of strings & numbers? I saw ord() for getting ASCII code in python & chr() for converting ASCII codes to characters somewhere & tried to use them to get answer of this question but it did not work!! :(
strings are sortd out by str(input) while numbers are sorted out by int(input)
wrong concept .plz correct it acc to uyou when i will take 21 as ainput it will show it is prime no. as 21%2==1 but 21 is not a prime nno. ur soln is for even no.
If we use negative value then error occur...
Wt happend if we not type a break
you won't get proper output:)
When we get divisor of given number then we know that number is not prime so we need to come out of the loop that's why we used break
:)
Plz tell with while loop
Instead of this large code..
We can do.. Num modulus 2 Or 3....remainder not eaual to 0 then it's PRIME NUMBER
That’s what we are doing here 😊
@@AmulsAcademy please make video on python interview programming question..
But not mcq... Something like paragraph narrated question....
Need it because I am final year student.. Please
@@AmulsAcademy sry but i thinks its a wrong code bcz for 21,9 it will show prime.
Thanks
but if i input 2 it comes out nothing, i know it is a prime number
plz tell me if num = 2
2 is a prime number:)
there is some mistake in your code see carefully
@kumari sonali ,code is working fine,give lower bound as 2,then it will print including with 2
One correction it is remainder not reminder
try 15 and see what output you will get
15 is not prime number :)
while True:
print(" thankyou very much")
Welcome :)
try 15 it is showing a prime no.
No it won't print 15 as prime number
:)
TYSM!!
Pleasure :)
As per your code, I given 111 and 333 then it is showing both prime and not prime, don't know why it is showing like that. CODE: #For checking prime number
num = int(input("Enter the number:"))
if num>1:
for i in range(2,num):
if (num%i)==0:
print(num, "it is not a prime number")
break
else:
print(num, "It is prime number")
else is for, for loop not for if condition.
num = int(input("Enter the number:"))
if num>1:
for i in range(2,num):
if (num%i)==0:
print(num, "it is not a prime number")
break
else:
print(num, "It is prime number")
:)
Same
plese insert by with alagorithm
if num=2
then the remainder will become zero
so how it is a prime
anyone??
when num=2 it won't execute the for loop body.
range(2,num) so it will become range(2,2) it won't give any value.
:)
So what shall we do ao that it get printed 2 is a prime number?
@@itsmeaman143 set the range from (2, num//2) it"ll return 2 as prime
its remainder not reminder lmao
please check your code as its a wrong code.
*remainder