+ 4
I can't figure out why this script shows no output can anybody help out?
It's a script to generate all prime numbers till an upper limit to print in a list https://code.sololearn.com/c01KdPuDZ2R0/?ref=app
11 Answers
+ 2
Fixed multiple errors in comments
ty Jayakrishna🇮🇳 ℂ𝕙𝕚𝕘𝕠𝕫𝕚𝕖 𝔸𝕟𝕪𝕒𝕖𝕛𝕚🇳🇬
+ 3
Not understood your logic of divisors..
But your while loop is an infinite loop..
You are not incrementing s..
Use this code sample there :
while s<l:
if is_prime(s):
print(s)
yield s
s+=1
"""
instead of this :
while s<l: #always true as s is not updated
if is_prime(s):
yield s
else:
continue
"""
+ 2
Ty Jayakrishna🇮🇳 i didn't notice that, so the divider() is called using 2 parameters the number to check and its half so it checks if the number is divisible by its half and decrement and checks again
+ 2
ℂ𝕙𝕚𝕘𝕠𝕫𝕚𝕖 𝔸𝕟𝕪𝕒𝕖𝕛𝕚🇳🇬 Thanks it clicked only when Jayakrishna🇮🇳 said it
+ 1
Try adding return
+ 1
Mention a example?
And divisor function either return false or none. Because you are not returning True. hence isPrice() never returns true, now. I tested adding it but can't find what's you are trying by that logic... You can go simple logic of for i in range(3 to N) , N%i return false
For 0,1 return false, for 2 return True. But first add a sample of divisor logic, I mean ex for (2,4)
+ 1
Jayakrishna🇮🇳 so, it worked thank you is price was never returning true as i intended it to be I can't understand the logic you proposed on the second comment but mine is working fine i think
+ 1
Yeah my bad i was talking bout the other continue
0
If it works then fine.
Note that, take out s+=1, you can remove else. The continue has no meaning to use as it continues without it.
You're welcome..
0
If there is no continue the if block will be empty and thus breaks it right?
0
Not understood your question but your code sample , this is :
while s<l:
if is_prime(s):
yield s
s+=1
else:
s+=1
continue
Equalent to :
while s<l:
if is_prime(s):
yield s
s+=1
works same.....!!!
Both if-else has s+=1 so take it out.
Continue is the last statement, without /with same happens then it's an extra line., and no need else then.