Комментарии:
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)
How to count them ?
ОтветитьJust curious: why didn't you create a function?
ОтветитьThank you sir love for Bangladesh
Ответитьthank you!
Ответитьsir can you write it without using a break command
Ответить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~~
ОтветитьThank you
ОтветитьThank you 😊 thank you sooo much 🙏🙏🙏
ОтветитьThank you for this!!
Ответить190th like
Ответить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)?
ОтветитьIn pydroid it doesnt work but in pycharm it works i must have a stupid IDE
ОтветитьHow about while loop?
Ответить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
How to get all that output in single line
Ответить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...
Ответить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
ОтветитьFor some reason, I copied this exactly into IDLE and it is only printing "2". Nothing else
Ответить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.
ОтветитьThanks
Ответить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
As a beginner in coding that else statement outside for loop felt genius
Ответитьshort and crisp!
ОтветитьVery helpful video for me.Thanks sir
ОтветитьThanks a lot!
Ответить