+ 6

Need help

Why this code that must find prime nubers from 3 to 100 includes 95 in the list? Please tell me what I'm doing wrong!! https://code.sololearn.com/ca4yn2obWt7f/?ref=app

7th May 2018, 1:08 PM
alfa6
alfa6 - avatar
4 Respostas
+ 6
I found your mistake, it's in line 14 You only set the divisor b to 2 if you found a prime number as it is inside the if block. You need to put the b = 2 back by 3 spaces to reset the divisor also after every no-prime number as well. It starts at 93/30 with 93%30 = 0 and the b goes on with 31-95 but b has to be 5 to show that 95 is no prime number. Hope you got me 😅
15th Jul 2018, 3:09 AM
Martin Möhle
Martin Möhle - avatar
+ 6
15th Jul 2018, 8:22 AM
Martin Möhle
Martin Möhle - avatar
+ 4
Thank you a lot! Now it works
15th Jul 2018, 8:18 AM
alfa6
alfa6 - avatar
+ 2
Looking into it... Maybe try adding a 3rd variable? Maybe it'll work, maybe not. I've seen a lot with different methods, yours seems quite unique.
7th May 2018, 1:54 PM
What was my name again?
What was my name again? - avatar