😎Hey, thanks for watching! We’d love to know your thoughts/doubts here in the comments. 👉For professional self-paced certification courses (pre-recorded), visit: bit.ly/Pre-Recorded-Course 👉Don’t forget to SUBSCRIBE to our channel for more such videos & valuable content: bit.ly/KZbin-WsCubeTech
@saurabhsingh523610 күн бұрын
Understanding the else in a for loop: • The else block after a for loop executes only if the loop is not terminated by a break statement. • In this case, the else block is executed if no divisors are found for the current num. Step-by-Step Execution: 1. Outer loop (for num in range...): • Iterates through numbers between Lower and upper + 1. 2. Inner loop (for i in range(2, num)): • Checks divisors of num starting from 2 up to num - 1. • If a divisor is found (num % i == 0), the break statement terminates the loop. 3. Else block: • Executes only if the inner for loop completes without a break (i.e., num has no divisors and is therefore prime).
@vaibhavv475 Жыл бұрын
More explanation is needed as to how the value continues to be printed......
@PythonProjectSolver11 ай бұрын
why 2 is consider as a prime number? because when 2 going to second for loop it is range of (2,2) than it check 2%2 that is equal to 0 than that is not a prime number. the solution is : find_p = range(1, 101) for p in find_p: if p > 1: for x in range(2, int(p**0.5) + 1): if p % x == 0: break else: print(p)
@venkatagovindpiradi13975 ай бұрын
I'm also thinking the same😢
@sushantchougale68182 жыл бұрын
Thank you very much Madam 😊
@Picture_of_truth5 ай бұрын
start=int(input("enter starting no:")) end=int(input("enter ending no:")) num=0 for num in range(2,end): for i in range(2,num): if num%i==0: break; else: print(num)
@shaikhkashif99739 ай бұрын
Thanks
@velocxty2477 Жыл бұрын
Great explanation ma’am!⚡️
@durgaprasadbandari9684 ай бұрын
great explanation
@bhavyasachula7006Ай бұрын
thanks a lott
@__ayu Жыл бұрын
THANK YOU...
@Neerajahir02.ahir.2 жыл бұрын
Nice
@agrimgupta08056 ай бұрын
we can make it more optimized?
@ashsaha5750 Жыл бұрын
Code is not working... Expexted indented block saying... irritating
@mohammadajharuddeen89332 жыл бұрын
Reach native ka full course upload kro please
@Abdul-tu6mq8 ай бұрын
Sprrrrrrrrr maam
@dawood35786 ай бұрын
mam I have a question. If I try to print else: statement with a tab space, right under second if, it prints the prime number more times than one. But when I write it like you have, behind the if: statement, it prints correctly. Isn't it necessary to use else: directly under if: statement. Please let me know. Thanks!
@ROHITH_PRO_513 ай бұрын
Same doubt bro
@nayansharma22420 күн бұрын
same doubt
@saurabhsingh523610 күн бұрын
@@nayansharma224 Understanding the else in a for loop: • The else block after a for loop executes only if the loop is not terminated by a break statement. • In this case, the else block is executed if no divisors are found for the current num. Step-by-Step Execution: 1. Outer loop (for num in range...): • Iterates through numbers between Lower and upper + 1. 2. Inner loop (for i in range(2, num)): • Checks divisors of num starting from 2 up to num - 1. • If a divisor is found (num % i == 0), the break statement terminates the loop. 3. Else block: • Executes only if the inner for loop completes without a break (i.e., num has no divisors and is therefore prime).
@ArtiKumari-rb6lj Жыл бұрын
Ma'am prime number repeated in output.
@Harshdhillon Жыл бұрын
Don’t print them in for loop break out from it
@KritarthShuklaA Жыл бұрын
Apna indentation check kro
@PannaLal-y7o9 ай бұрын
Same problem
@a.dashish28446 ай бұрын
Your second If and else statment must in the block first range function
@a.dashish28446 ай бұрын
x = int(input(" x: ")) y = int(input(" y: ")) for i in range(x, y+1): if i > 1: # Ensuring we only consider numbers greater than 1 for m in range(2, i): if i % m == 0: break else: print(i) # Only prints if no divisor was found
@ammarahmad70362 жыл бұрын
It's true
@mekalachinnikrishna8372 Жыл бұрын
Mam we are using num here but we are not defined num then how your output will come
@Nannu-l4i Жыл бұрын
Cz num koi variable ni h jisme values store krvai ho , simply "i" ko replace Kia h "num" se ,which means items in that range of numbers
@swastikpanda56704 ай бұрын
this is my code yet i am not getting the correct output: a=int(input("a: ")) # b=int(input("b: ")) # num=0 # for num in range (a,b+1): # if num>1: # for i in range(2,num): # if num%i==0: # break # else: # print(num)
@Ram-yw5ky2 ай бұрын
Num_s = int(input("Enter no =")) end_s = int(input("Enter no =")) for num in range(Num_s,end_s + 1): if num > 1: for i in range(2,num): if num%i == 0: break else: print(num) break Mam mei code run kr rha fir bhi 9 prime kyu show kr rha
@saiishwarya812Ай бұрын
Because you are writing else statement inside the for In this case while checking for first iteration only it will show as prime
@kshitijsahdev44803 ай бұрын
"Herro everyone" 😂
@MuhammadAwais-yt6je2 жыл бұрын
Unreal engine 5 ka b cours layaa
@ichchakushwaha3209 Жыл бұрын
hey i printed "num+1 " at the place of "num", and not getting the "2" in output as a prime number l=int(input("lower limit: ")) u=int(input("upperr limit: ")) for num in range(l,u+1): if num>1: for i in range(2,num+1): if num%i==0: break else: print(num) break this is my code
@GamingGalaxyFF Жыл бұрын
remove the last break command then it will work😊
@AryanHuria Жыл бұрын
Hey you are doing in second loop num+1 , then it's wrong suppose from the first loop you took 99 , and the second loop gets divided by 99 , if you will write num+1 , it will get divided by 99 too and therefore program won't return a single prime number.
@shashankpandey518710 ай бұрын
check indentation once(your else statement)
@AmaanKhan-cb4rn Жыл бұрын
❤❤❤
@skcreates3432 жыл бұрын
Mai es video par pahli baar aaya hu or Python learn karna chahta hu. Kya hum Python me koi app devlop kar sakte hai ? Kya hum Python se online tool bana sakte hai ? Can you guide me god bless you 🙏🙏🙏🌸🌸
@TilakRaj-qo6ic Жыл бұрын
Python is becoming a general purpose language slowly so you can do anything you want
@Cyclopentasi1_oxane Жыл бұрын
i%j==0. Ie... 2%2==0.... thats right? Then how 2 printed in prime
@kishorem546111 ай бұрын
Same doubt
@zulfiquarshaikh346111 ай бұрын
@wscubetech pls explain if 2%2 ==0 , then how 2 is getting printed in output
@PythonProjectSolver11 ай бұрын
this is correct code : find_p = range(0, 100) for p in find_p: if p > 1: for x in range(2, int(p**0.5) + 1): if p % x == 0: break else: print(p)
@PythonProjectSolver11 ай бұрын
this is correct code : find_p = range(0, 100) for p in find_p: if p > 1: for x in range(2, int(p**0.5) + 1): if p % x == 0: break else: print(p)@@kishorem5461
@PythonProjectSolver11 ай бұрын
@@zulfiquarshaikh3461 this is correct code : find_p = range(0, 100) for p in find_p: if p > 1: for x in range(2, int(p**0.5) + 1): if p % x == 0: break else: print(p)