Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

My code is working and all is fine, I was trying to adjust it by making b=1 (in whichprimes function) from it being b = 3. I dont see why changing b from 3 to 1 changes anything and it really bugs me. Maybe you can tell. http://codepad.org/UFvbsPfe As mentioned on top, the thing I dont understand is why the code doesnt work if I make b = 1 if its b =3, it works fine. if its b = 1, it returns primes list with only 2 in it

OpenStudy (anonymous):

Here is your code with some extra print lines, b =1, and a test of the function on 10: http://codepad.org/AUsN4d4i Your problem is that your b value doesn't seem to be increasing. Im not entirely sure why that is...but when b = 1 it doesn't seem to increase

OpenStudy (anonymous):

http://codepad.org/u5PG5hJo One thing I noticed is that you weren't implementing your range correctly again, like last time, so all I did was change the starting range for line 12 to 0. Keep in mind this means its looping from 0-4, NOT 0-5. But that's what you want, since len(lodds) is 5 and 0-4 calls all 5 of those indices. Again though this is still written better if you just do for i in lodds instead, calling with i instead of lodds[i]. I don't think this fixes your problem but hopefully it's a step in the right direction.

OpenStudy (anonymous):

The fix, I believe, is in the bad if statement in the case b = 1; i.e., it would return false at first try because lodds[i]%1 == 0 and lodds[i]!=1; I tried: if lodds[i] % b == 0 and b!=1:(line 14), with the rest of the code remaining the same, and it worked.

OpenStudy (anonymous):

The main reason you can't get it to work is that you're trying to do too many things at once. First, just write a loop that determines if a single number is prime or not. Your inner loop isn't doing that correctly. Don't attempt to find multiple primes until you can get just that code to work, in isolation.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!