Python Program to Print all Prime Numbers in an Interval - Complete Tutorial

  Рет қаралды 75,056

WsCube Tech

WsCube Tech

Күн бұрын

Пікірлер: 52
@wscubetech
@wscubetech 2 жыл бұрын
😎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
@saurabhsingh5236
@saurabhsingh5236 10 күн бұрын
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
@vaibhavv475 Жыл бұрын
More explanation is needed as to how the value continues to be printed......
@PythonProjectSolver
@PythonProjectSolver 11 ай бұрын
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)
@venkatagovindpiradi1397
@venkatagovindpiradi1397 5 ай бұрын
I'm also thinking the same😢
@sushantchougale6818
@sushantchougale6818 2 жыл бұрын
Thank you very much Madam 😊
@Picture_of_truth
@Picture_of_truth 5 ай бұрын
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)
@shaikhkashif9973
@shaikhkashif9973 9 ай бұрын
Thanks
@velocxty2477
@velocxty2477 Жыл бұрын
Great explanation ma’am!⚡️
@durgaprasadbandari968
@durgaprasadbandari968 4 ай бұрын
great explanation
@bhavyasachula7006
@bhavyasachula7006 Ай бұрын
thanks a lott
@__ayu
@__ayu Жыл бұрын
THANK YOU...
@Neerajahir02.ahir.
@Neerajahir02.ahir. 2 жыл бұрын
Nice
@agrimgupta0805
@agrimgupta0805 6 ай бұрын
we can make it more optimized?
@ashsaha5750
@ashsaha5750 Жыл бұрын
Code is not working... Expexted indented block saying... irritating
@mohammadajharuddeen8933
@mohammadajharuddeen8933 2 жыл бұрын
Reach native ka full course upload kro please
@Abdul-tu6mq
@Abdul-tu6mq 8 ай бұрын
Sprrrrrrrrr maam
@dawood3578
@dawood3578 6 ай бұрын
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_51
@ROHITH_PRO_51 3 ай бұрын
Same doubt bro
@nayansharma224
@nayansharma224 20 күн бұрын
same doubt
@saurabhsingh5236
@saurabhsingh5236 10 күн бұрын
@@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
@ArtiKumari-rb6lj Жыл бұрын
Ma'am prime number repeated in output.
@Harshdhillon
@Harshdhillon Жыл бұрын
Don’t print them in for loop break out from it
@KritarthShuklaA
@KritarthShuklaA Жыл бұрын
Apna indentation check kro
@PannaLal-y7o
@PannaLal-y7o 9 ай бұрын
Same problem
@a.dashish2844
@a.dashish2844 6 ай бұрын
Your second If and else statment must in the block first range function
@a.dashish2844
@a.dashish2844 6 ай бұрын
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
@ammarahmad7036
@ammarahmad7036 2 жыл бұрын
It's true
@mekalachinnikrishna8372
@mekalachinnikrishna8372 Жыл бұрын
Mam we are using num here but we are not defined num then how your output will come
@Nannu-l4i
@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
@swastikpanda5670
@swastikpanda5670 4 ай бұрын
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-yw5ky
@Ram-yw5ky 2 ай бұрын
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
@saiishwarya812 Ай бұрын
Because you are writing else statement inside the for In this case while checking for first iteration only it will show as prime
@kshitijsahdev4480
@kshitijsahdev4480 3 ай бұрын
"Herro everyone" 😂
@MuhammadAwais-yt6je
@MuhammadAwais-yt6je 2 жыл бұрын
Unreal engine 5 ka b cours layaa
@ichchakushwaha3209
@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
@GamingGalaxyFF Жыл бұрын
remove the last break command then it will work😊
@AryanHuria
@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.
@shashankpandey5187
@shashankpandey5187 10 ай бұрын
check indentation once(your else statement)
@AmaanKhan-cb4rn
@AmaanKhan-cb4rn Жыл бұрын
❤❤❤
@skcreates343
@skcreates343 2 жыл бұрын
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
@TilakRaj-qo6ic Жыл бұрын
Python is becoming a general purpose language slowly so you can do anything you want
@Cyclopentasi1_oxane
@Cyclopentasi1_oxane Жыл бұрын
i%j==0. Ie... 2%2==0.... thats right? Then how 2 printed in prime
@kishorem5461
@kishorem5461 11 ай бұрын
Same doubt
@zulfiquarshaikh3461
@zulfiquarshaikh3461 11 ай бұрын
@wscubetech pls explain if 2%2 ==0 , then how 2 is getting printed in output
@PythonProjectSolver
@PythonProjectSolver 11 ай бұрын
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)
@PythonProjectSolver
@PythonProjectSolver 11 ай бұрын
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
@PythonProjectSolver
@PythonProjectSolver 11 ай бұрын
@@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)
@ZenBeats01
@ZenBeats01 2 жыл бұрын
❤️❤️
@muzamilrana8854
@muzamilrana8854 2 жыл бұрын
1st comment😍
@sakshikadu7722
@sakshikadu7722 Жыл бұрын
i kya h
@Nannu-l4i
@Nannu-l4i Жыл бұрын
Items in range(0, upto to given num)
Solve any Star Pattern program in Python
18:44
Simply Coding
Рет қаралды 1 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 16 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 26 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 21 МЛН
Find the Factorial of a Number - Python Program Tutorial🔥
14:58
Python Tutorial - Prime Numbers | Printing Prime Numbers in Given Interval
18:33
you need to learn Python RIGHT NOW!! // EP 1
17:42
NetworkChuck
Рет қаралды 2,5 МЛН
Israel Has The Right To Defend Itself | Stand-up Comedy by Daniel Fernandes
15:07
Fibonacci Sequence: Python Tutorial for Beginners
9:20
WsCube Tech
Рет қаралды 69 М.
Python Program #17 - Check Armstrong Number in Python
8:44
Programming For Beginners
Рет қаралды 14 М.
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 16 МЛН