I just want to say one thing. Watched 10 videos but none of them were this good. Thank you so much. Hitting like and subscribe. For beginners this video is must.
lower=int(input('lower')) upper=int(input('upper')) for num in range (lower,upper+1): if num>1: for i in range (2,num): if num%i==0: break else: print(num)
very very very thanks for this understand ................... no words are coming finally after 3 days of madness in loops got this amazing,exellent vedio...... wow
It will print nothing. In this case, if your "num" is two(2), it means you would have given your upper limit as two(2).In range, it will take only (n-1) values. So that would print nothing. As it would be like (2,1), I suppose.
Hopefully one day you definitely taking gold play button for such amazing content you deserve more and more subscribers Thank you for providing such amazing content mam
maam, i am not able to understand how 2 is getting printed if we use 2 as our lower limit. 2 will get divided by range(2,1) hence will break out from the loop and nothing should be printed. please reply
We took range form 2 to num. {for i in range(2,num)} when num is 2 range will become range(2,2) so it won't execute for loop body so it will execute else part and it will print 2 as prime number.
Hey amulya I have watched a video for prime numbers... I cant remember but it was like for i in range(2,n//2+1): If n%i ==0: break else: print(n) Is it true
Wow what an explanation mam, today I saw your channel and this video first time ,now I have subscribed this channel bcoz my query has solved here only tysm mam please come up with such more videos🙏🙏
We can use else with loops, for and while loop. And here we can't use else part with if . If i use that i won't get proper output. for i in range(2,num): if (num % i) == 0: print(num,"is not a prime number") print(i,"times",num//i,"is",num) break else: print(num,"is a prime number") for example: take number 21 control goes to if condition and it will check, if 21%2==0 No so it come out of the if body and execute else part, that is it will print message 21 is prime number, but it is not. i need to check all divisors right. So we can't write like this. We are using for - else because it will check whole for loop body, it will divide the number with every other number starting from 2 and if that number is not divisible then we will print the message that is "not prime number". :)
@@AmulsAcademy I was having the same question thnx for answering , actually no one explains this for-else loop nor I find it on any website so it's a bit confusing
@@AmulsAcademy I have another doubt. If I use print(i, end=",") as you said, I get comma at the end of the number. That is , my lower range is 1 and my upper range is 10. My prime numbers are2,3,5,7 . If I use end="," in print , i get my output as 2,3,5,7, . I get comma at the end of 7. How to avoid this.
I understood. This reply is for those who didn't understand for 2. If your Lower limit is 2. It's 2 > 1 but when 2 will go to the (2, num) loop. It will become (2,1) because num will be excluded. So it will directly go to the print(num) function.
Would this code work or not if not then plzz tell me why no = int(input("enter the no")) count = 0 for j in range (1,no+1): for i in range(1,j+1): if j%i == 0: count+=1 if count == 2: print(i) else: pass
The inner loop iterations can be reduced to half. lower = int(input("Enter the lower interval")) upper = int(input("Enter the upper interval")) for j in range(lower, upper+1): if j > 1: for i in range(2,j//2): #
In case if we have to check only one input number is prime or not then how can we do it??? Another one that we know that 1 is prime number but by using this code we can't get result as 1 is prime number as u mentioned number > 1. So how we check 1 is prime number or not???
In range function, end is exclusive. syntax of rang function is, range(start,end,step) if you want to print 1 to 10 numbers then you need to take range as, range(1,11) try this: for i in range(1,11): print(i) :)
I tried using without break statement in this code...I have given number as 9..output as showing as 9 is not a prime number and 9 is a prime number Num=int(input("enter a number:")) If num>1: For I in range(2,num): If num%i==0: Print num,"is not a prime number" Else: Print num,"is a prime number" Else: Print num,"is a prime" Pls explain
When i know there is a number which divides entered number then i know that number is not prime , so when for i in range(2,num): if num%i==0: This condition becomes true then i will print number is not prime and i don't want to execute anything else, so i used break statement there. for example if i take number as 16, first i will check whether 16 is divisible by 2 if yes then i won't check further , i know 16 is not prime so i will print that and stop execution. in your case you are not using break statement, so when i take number as 9, it will check 9%2==0 no so it will check 9%3==0 yes , so it will print 9 is not prime number, but again continue with the for loop, so it will check 9%4==0.... till i =8 ok. here if any other number divides 9 then again the massage "9 is not prime number" will be printed. After that control comes out of the loop , and it will execute else part because , The else block just after for/while is executed only when the loop is NOT terminated by a break statement. Ok so you will get 9 is prime number message also :)
i dont understand how 2 is printed when (2%2 == 0) if u take range from 2 to 15 instead of 5 ...how 2 is printed when its remainder is 0 when divided by 2...but your code is printing 2 how ?
for i in range(2,num): if (num % i) == 0: when num =2, for i in range(2,2) : so it won't execute for loop body, control goes to else part directly. so it won't execute if condition. If you have still confusion, execute this piece of code for i in range(2,2): print("h") else: print("a") in range() start and end value is same it won't execute the for loop. :)
lower = 900 upper = 1000 print("Prime numbers between",lower,"and",upper,"are:") for num in range(lower,upper + 1): if num > 1: for i in range(2,num): if (num % i) == 0: break else: print(num, end=",") print(end=".") In print() take end =coma :)
is it correct? lower=int(input("enter the lower limit")) upper=int(input("enter the upper value:")) for num in range(lower,upper): if num>1: for i in range(2,num): if num%i==0: print(num,"not prime") break else: print(num,"prime")
how do you count the length of "num" i tried: n=999 for num in range(0,n+1): if num>1: for i in range(2,num): if(num%i)==0: break else: print(len(num)) could you help?
@@AmulsAcademy n=999 for num in range(0,n+1): if num>1: for i in range(2,num): if(num%i)==0: break else: print(num) sum(int(num)) I don't know how to get it to work?
Thank you! This was probably my 10th video trying to figure this out , and i think i finally got it. You're very good at explaining.
Have been struggling with understanding this and suddenly stumbled on this.
So explanatory. Thank you for your effort.
I just want to say one thing. Watched 10 videos but none of them were this good. Thank you so much. Hitting like and subscribe. For beginners this video is must.
Amazing teacher, finally I understood all I needed so far...beginner. Thank you
My Pleasure :)
You explain a complex thing in a wonderful and extraordinary manner. Great!
Thank you! 😃
Amulya's Academy Has Its Own Style Of Teaching .One Of The Best Channels On RUclips 🙌🙌🙌💥🔥🤑👏👏Thanks Mam!!!!
Thank you :)
My greatest tutor ,I appreciate your work you're doing for us
Thank you 😊
You are such a great teacher , thank for helping people , great jobs
your voice makes it interesting , but your expalanation is magic
Thank you :)
lower=int(input('lower'))
upper=int(input('upper'))
for num in range (lower,upper+1):
if num>1:
for i in range (2,num):
if num%i==0:
break
else:
print(num)
you are my best teacher in the world. thank sister.
My Pleasure :)
This is the best video i ever watched for python programming. This is really begginer friendly.
u r awsome sis if u were my python teacher i will topper in my class ❤❤☺☺☺
Yes ,
But I want modules,
Unittest
Threading,
Logging,
Paramiko,
For these models videos
You are learning python for marks wow
Congratulations sis
No
Yes same feelings
very very very thanks for this understand ................... no words are coming finally after 3 days of madness in loops got this amazing,exellent vedio...... wow
Your way of teaching is very nice mam... Easily understood
Thank you :)
Hi, I have a question about what if 2 in the range(2, num), the range will be (2,2) which has no number contained.
It will print nothing. In this case, if your "num" is two(2), it means you would have given your upper limit as two(2).In range, it will take only (n-1) values. So that would print nothing. As it would be like (2,1), I suppose.
@@harikrishnants8545 then how she get 2 in the second example
Your tutorials are better than udemy.
Thank you:)
Hopefully one day you definitely taking gold play button for such amazing content you deserve more and more subscribers
Thank you for providing such amazing content mam
Thank you so much 😀
*Amazing*... Thanks a lot for helping me mam 😃😁😀
Pleasure :)
Amuls Academy mam can u make practice programs in dictionary also ...it's a quit important topic . They ask in exam
It's awesome . The way you explained was too basic and it's really helped me to understand internal loop flow.
Pleasure :)
2 cute voices in youtube..
1,strell
2,your's
Awesome class tnx mam
Thank you :)
@@AmulsAcademy a
This video was Very clear explanation compare to other videos.....Thank you so much mam......
Your explanation is crystal clear! ❤
Thank you :)
will you plz explain once
will this program work if we take lower value as 2 ???
Thank you so much .now i m getting confident in coding because of ur video..love and respect🙏🙌❤
Thank you so much! You are great at explaining the logic behind the code for novices like me.
Wow!! Nice explanation
Finally i got the logic for prime number
I appreciate ur work
Glad to hear that :)
@@AmulsAcademy have u uploaded prime number using while loop because its way too confusing in while loop
maam, i am not able to understand how 2 is getting printed if we use 2 as our lower limit. 2 will get divided by range(2,1) hence will break out from the loop and nothing should be printed. please reply
We took range form 2 to num. {for i in range(2,num)}
when num is 2
range will become range(2,2)
so it won't execute for loop body so it will execute else part and it will print 2 as prime number.
subscribed!!! But 1 request is you have to upload daily basis video on python
Hats off ❤🎉
what is the execution if inner loop range is (2,2)
Same doubt
Hey amulya
I have watched a video for prime numbers...
I cant remember but it was like
for i in range(2,n//2+1):
If n%i ==0:
break
else:
print(n)
Is it true
Yes i think this will work :)
@@AmulsAcademy pls explain this
Than you so much mam,ur explanation will be change us ,please come again with more video to improve us mam
Pleasure 😊
I have done what you did but then many of the numbers ended up printing multiple times. Can someone help me with this?
Break the statement after one loop
Wow what an explanation mam, today I saw your channel and this video first time ,now I have subscribed this channel bcoz my query has solved here only tysm mam please come up with such more videos🙏🙏
Wow..!!
Excellent explanation ma'am
Thank you :)
Your explanation is best
Thanks a lot 😊
Why ELSE part is written below FOR, not below IF?
We can use else with loops, for and while loop.
And here we can't use else part with if .
If i use that i won't get proper output.
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
for example:
take number 21
control goes to if condition and it will check,
if 21%2==0
No
so it come out of the if body and execute else part, that is it will print message 21 is prime number, but it is not.
i need to check all divisors right.
So we can't write like this.
We are using for - else because it will check whole for loop body, it will divide the number with every other number starting from 2
and if that number is not divisible then we will print the message that is "not prime number".
:)
@@AmulsAcademy Thank you so much. I have the same question. it really makes sense to me now.
@@AmulsAcademy I was having the same question thnx for answering , actually no one explains this for-else loop nor I find it on any website so it's a bit confusing
Tnq for clean n crisp explanation. Keep uploading.. Lots of love from Visakhapatnam
Thank you :)
@@AmulsAcademy what if the lower value starts from 2
thank you very much mam! really your all lectures are very helpful for me.
i was looking for a set of programming examples to practice...its great that i found your playlist!...solving the problems with proper explanation, tq
Glad it was helpful! :)
Mam excellent teaching 😊😊😊
Thanks a lot :)
Mam is there machine learning and artificial intelligence in your academy
If it is there, please send me the link .If it is not there please make a tutorial on it🙏🙏🙏🙏
i want to know why you are printing else statement in the line of for loop rather than if statement
???
We can use else with loops also, and here we need else with while loop 😀
Mam only this method can use Or other methods r in there
I want numbers in single line and I want comma in between numbers. What can I do
use end parameter . you can try end="," in print function
@@AmulsAcademy Thank you
@@AmulsAcademy I have another doubt. If I use print(i, end=",") as you said, I get comma at the end of the number. That is , my lower range is 1 and my upper range is 10. My prime numbers are2,3,5,7 . If I use end="," in print , i get my output as 2,3,5,7, . I get comma at the end of 7. How to avoid this.
Very well explained !!! Keep it up
best teacher ...
Thank you :)
Bro, what about num=2 and i=2 case
So the loop will break, but 2 is prime
Please explain
Great teaching ma'am
Thanks a lot :)
Nice explanation.
Thank you :)
thanks mam u r really awesome i was not able to understand about num function in this code but u cleared my doubt thanks a lot again
You are welcome 😊
awesome video Sister,your videos helps me lot......................
Thank you:)
Mam what about 2. 2 is also prime number, but after if statement is true, break statment will execute and I think its a loop. Pls explain
I understood. This reply is for those who didn't understand for 2. If your Lower limit is 2. It's 2 > 1 but when 2 will go to the (2, num) loop. It will become (2,1) because num will be excluded. So it will directly go to the print(num) function.
Would this code work or not if not then plzz tell me why
no = int(input("enter the no"))
count = 0
for j in range (1,no+1):
for i in range(1,j+1):
if j%i == 0:
count+=1
if count == 2:
print(i)
else:
pass
Thank you Amul for a very well presented lesson. Thanks to you I now understand !
My Pleasure :)
I liked your voice and way of explanation very nice...really satisfied your channel name amuls..thanks soo much
The inner loop iterations can be reduced to half.
lower = int(input("Enter the lower interval"))
upper = int(input("Enter the upper interval"))
for j in range(lower, upper+1):
if j > 1:
for i in range(2,j//2): #
Thanks
In case if we have to check only one input number is prime or not then how can we do it??? Another one that we know that 1 is prime number but by using this code we can't get result as 1 is prime number as u mentioned number > 1. So how we check 1 is prime number or not???
To check entered number is prime or not:
ruclips.net/video/je9FcxgLBf4/видео.html
1 is not a prime number.
:)
Explain me please, why you added
" +1" the beginning .
For num in range (lower, upper +1) , I ran without "+1" and it worked.
In range function, end is exclusive.
syntax of rang function is,
range(start,end,step)
if you want to print 1 to 10 numbers then you need to take range as,
range(1,11)
try this:
for i in range(1,11):
print(i)
:)
Amuls Academy I understood. Thank you 🤗
Has to really appreciate how well u explain everything 🙏🏻❤️💯
its awesome tomorrow is my exam I hope I will do better tomorrow !😊😊
I tried using without break statement in this code...I have given number as 9..output as showing as 9 is not a prime number and 9 is a prime number
Num=int(input("enter a number:"))
If num>1:
For I in range(2,num):
If num%i==0:
Print num,"is not a prime number"
Else:
Print num,"is a prime number"
Else:
Print num,"is a prime"
Pls explain
When i know there is a number which divides entered number then i know that number is not prime , so when
for i in range(2,num):
if num%i==0:
This condition becomes true then i will print number is not prime and i don't want to execute anything else, so i used break statement there.
for example if i take number as 16,
first i will check whether 16 is divisible by 2 if yes then i won't check further , i know 16 is not prime so i will print that and stop execution.
in your case you are not using break statement,
so when i take number as 9, it will check 9%2==0 no
so it will check 9%3==0 yes , so it will print 9 is not prime number,
but again continue with the for loop,
so it will check 9%4==0.... till i =8 ok.
here if any other number divides 9 then again the massage "9 is not prime number" will be printed.
After that control comes out of the loop , and it will execute else part because ,
The else block just after for/while is executed only when the loop is NOT terminated by a break statement.
Ok so you will get 9 is prime number message also
:)
@@AmulsAcademy thank you so much
hey 9 is not a prime number
Thank you so much mam ur videos are Very helpful... please keep going
Thank you :)
Amul good job...but I have a small doubt ..here u used else condition may I know it belongs to which if condition...
else is for, for loop :)
Mam, how did this logic work for when num is 2
Coz 2%2==0
Range from 2, num means num will not be included in the for loop
@@reetasharma7505 : I didn't get it... can you please elaborate
for i in range(2, num)
when num=2
for i in range(2,2)
here range is from 2 to 2, so it won't execute for body.
:)
I am learning ,keep it up please
Thank you 😊
For which 'if loop' that 'else loop' is applied??
else part is used with for loop here :)
@@AmulsAcademy ok thanks got it
will ELSE work with FOR loop if it is C language
Thankyou for the incredible explanation.....
I love your teaching
you got a new subscriber!!😊😊👌😘👍👍
Welcome!! :)
i dont understand how 2 is printed when (2%2 == 0) if u take range from 2 to 15 instead of 5 ...how 2 is printed when its remainder is 0 when divided by 2...but your code is printing 2 how ?
yeah this is what my question also,,
for i in range(2,num):
if (num % i) == 0:
when num =2,
for i in range(2,2) : so it won't execute for loop body, control goes to else part directly. so it won't execute if condition.
If you have still confusion,
execute this piece of code
for i in range(2,2):
print("h")
else:
print("a")
in range() start and end value is same it won't execute the for loop.
:)
@@AmulsAcademy thanks sister
can you plzz tell for which num you define for eg if you choose two limits 5 and 35 so for which FOR loop from 2,num is applicable
Sorry i am not getting your question can you please explain little more?
Hey, I need to print the prime numbers separated by commas, how can I do that?
lower = 900
upper = 1000
print("Prime numbers between",lower,"and",upper,"are:")
for num in range(lower,upper + 1):
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
print(num, end=",")
print(end=".")
In print() take end =coma
:)
else:
print(num,end=",")
@@AmulsAcademy i dont understand the in print() part, it gives me an error
This is so nicely explained.Thank you!
Glad it was helpful! :)
Best explaination
Thank you :)
Ⓛⓞⓞⓢⓤ
Mam can you u tell me ...how to print the negative prime numbers
is it correct?
lower=int(input("enter the lower limit"))
upper=int(input("enter the upper value:"))
for num in range(lower,upper):
if num>1:
for i in range(2,num):
if num%i==0:
print(num,"not prime")
break
else:
print(num,"prime")
In the for loop use range as lower to upper+1 😊
Very lucid explanation ma'am
Thank you
your explanation is super.is this any possible to decrease the length of the programe ?
Aapka n *python tutorials* summe m bra aacha lgta h
thank you madam u are really teaching well
Pleasure :)
how do you count the length of "num"
i tried:
n=999
for num in range(0,n+1):
if num>1:
for i in range(2,num):
if(num%i)==0:
break
else:
print(len(num))
could you help?
convert num to string and use len() :)
@@AmulsAcademy
n=999
for num in range(0,n+1):
if num>1:
for i in range(2,num):
if(num%i)==0:
break
else:
print(num)
sum(int(num))
I don't know how to get it to work?
Could you please upload the video for difference between functions,class,attributes,methods and explain it clearly with one example...how all works
Ok i will try :)
Excellent explanation
Hi here how 2 is executed if I put 2 as upper limit
Excellent video
Thank you 😊
Valuable teaching.. 👍
Nice mam this was useful in my study📚✏
Nice Explanation Mam 👏
Excellent teaching
Thank you:)
superb 👌 could understand very easily. Thankyou ☺️
Most welcome 😊
Is it possible to use the condition
if (num%i)!=0:
mam can you help me to make a list of prime numbers in loop with yes or no to continue? im stuck with int not callable
Give me your program i will correct it.
:)
very well explained! appreciated! ( p.s its remainder not reminder 😅)
Haha… thank you 😊
Mam i dont get the indentation of else condition.
else is part for for loop, like if else we can use else with loops also. :)
Nice explanation
Thank you :)
Really good explanation mam!!!! 👍👍
simply superb 😍
Could someone please explain why the else statement is now a for-else statement? I never heard of that before.