I can't figure out why this script shows no output can anybody help out? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

2nd Feb 2022, 4:31 PM
Saviyo Thomas
Saviyo Thomas - avatar
11 Answers
3rd Feb 2022, 3:43 AM
Saviyo Thomas
Saviyo Thomas - avatar
+ 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 """
2nd Feb 2022, 4:43 PM
Jayakrishna 🇮🇳
+ 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
2nd Feb 2022, 5:12 PM
Saviyo Thomas
Saviyo Thomas - avatar
2nd Feb 2022, 5:15 PM
Saviyo Thomas
Saviyo Thomas - avatar
+ 1
Try adding return
2nd Feb 2022, 4:42 PM
Chigozie Anyaeji 🇳🇬
Chigozie Anyaeji 🇳🇬 - avatar
+ 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)
2nd Feb 2022, 5:38 PM
Jayakrishna 🇮🇳
+ 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
2nd Feb 2022, 7:03 PM
Saviyo Thomas
Saviyo Thomas - avatar
+ 1
Yeah my bad i was talking bout the other continue
2nd Feb 2022, 8:14 PM
Saviyo Thomas
Saviyo Thomas - avatar
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..
2nd Feb 2022, 7:20 PM
Jayakrishna 🇮🇳
0
If there is no continue the if block will be empty and thus breaks it right?
2nd Feb 2022, 7:36 PM
Saviyo Thomas
Saviyo Thomas - avatar
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.
2nd Feb 2022, 7:50 PM
Jayakrishna 🇮🇳