Python - Print All Prime Numbers In Any Interval

Python - Print All Prime Numbers In Any Interval

Wrt Tech

3 года назад

43,383 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@wrttech422
@wrttech422 - 24.11.2021 10:00

l = int(input("low bound: "))
u = int(input("upper bound: "))

for num in range(l,u+1):
if num > 1:
for i in range(2,num):
if num % i == 0:
break
else:
print(num)

Ответить
@reaxer3687
@reaxer3687 - 01.06.2023 18:05

How to count them ?

Ответить
@dries59dep
@dries59dep - 28.05.2023 02:17

Just curious: why didn't you create a function?

Ответить
@AmirAli-no8ye
@AmirAli-no8ye - 14.01.2023 23:35

Thank you sir love for Bangladesh

Ответить
@q1mora
@q1mora - 04.10.2022 18:44

thank you!

Ответить
@jadeboom9685
@jadeboom9685 - 27.09.2022 14:18

sir can you write it without using a break command

Ответить
@user-ds2vu7uy2q
@user-ds2vu7uy2q - 17.09.2022 13:04

wonderful, i really appreciate that. Yet i am wondering why the else can go outside the for loop but not on the same vertical line with 'if'. What does it mean sir, hope you can answer me~~

Ответить
@mus_3219
@mus_3219 - 01.06.2022 19:50

Thank you

Ответить
@S.ZT119
@S.ZT119 - 25.05.2022 13:45

Thank you 😊 thank you sooo much 🙏🙏🙏

Ответить
@chesb6426
@chesb6426 - 23.05.2022 13:15

Thank you for this!!

Ответить
@rohithkoushal5109
@rohithkoushal5109 - 23.03.2022 02:18

190th like

Ответить
@ayearninghope
@ayearninghope - 18.03.2022 16:18

If we know 2 isn't a factor of n, wouldn't it be better to avoid running this code over rest of the even numbers in our integer range (since even numbers are all factors of 2)?

Ответить
@10F2C
@10F2C - 06.03.2022 15:33

In pydroid it doesnt work but in pycharm it works i must have a stupid IDE

Ответить
@pakapeta7772
@pakapeta7772 - 09.02.2022 23:37

How about while loop?

Ответить
@telsaabi9865
@telsaabi9865 - 05.02.2022 02:26

How can we modify this so that given a positive integer x, it computes the fraction
f(x) of prime numbers less than or equal to x, i.e., f(x) = y/x, where y is the the number of prime
numbers less than or equal to x

Ответить
@chadvukondiifirstuu3231
@chadvukondiifirstuu3231 - 26.01.2022 06:52

How to get all that output in single line

Ответить
@cokfarm6373
@cokfarm6373 - 28.11.2021 16:01

how to write this code for, prime numbers between 100 & 200, and output as 5 numbers in 1 line and then next line, a little tricky question...

Ответить
@bhavanipullepu1416
@bhavanipullepu1416 - 24.11.2021 09:46

When i was doing this in the range between 1 to 10.....2 is not including in the list when the output was displayed......I dont know why it was not including....pls give me the solution sir

Ответить
@bryceberry5852
@bryceberry5852 - 14.11.2021 17:37

For some reason, I copied this exactly into IDLE and it is only printing "2". Nothing else

Ответить
@snehap7057
@snehap7057 - 05.11.2021 01:45

If finding prime number between 2 and 200, Does this function work? Because 2 divided by 2 will break and will not print 2, but 2 is a prime number.

Ответить
@killua7963
@killua7963 - 23.09.2021 19:20

Thanks

Ответить
@houseofelectronics5869
@houseofelectronics5869 - 09.09.2021 15:31

Great tutorial. Just a suggestion below
Instead of "for i in range(2,num)" ,
"for i in range(2,(num//2 + 1))" would have better time complexity isn't it? Because for any i which is greater than num/2 , num won't divide by i

Ответить
@naveenkumarg3015
@naveenkumarg3015 - 16.08.2021 11:16

As a beginner in coding that else statement outside for loop felt genius

Ответить
@vishnukantchaudhary285
@vishnukantchaudhary285 - 15.08.2021 01:08

short and crisp!

Ответить
@anasshahid8564
@anasshahid8564 - 23.06.2021 07:23

Very helpful video for me.Thanks sir

Ответить
@salad02
@salad02 - 19.06.2021 12:11

Thanks a lot!

Ответить