So I've been working on assignment two, and though I get no syntax error, when I run the program there is no output, so there must be something wrong with my logic here. Anyone mind checking it? http://dpaste.com/675856/
Now that I look at it again, I'm assuming the problem is that no divisor will cause the remainder to be 1 other than the original number, so there can be no output. I'm guessing that my divisor has to be a combination of two different odd numbers. Not sure how I'll get that to happen yet though.
if (oddNum%divisor == 1): should be if (oddNum%divisor == 0): I guess
Yeah thanks! I actually realized that after I responded to myself, and fixed that, but it still isn't creating output. I'm assuming its stuck in an infinite loop in some way,
You are in a infinite loop, you don't increment the value of divisor: divisor - 1 instead of divisor = divisor -1. And then you have still some logical failures ;-) But you will find them. It helps if you put print statements of values in your code, so you see the progression and how your values change (or not)
Oh didn't realize that was necessary. Thanks for all the help! Will try and figure out what's going wrong.
No worries, keep trying. Asking questions is free ;-)
Alright, so I followed your advice and realized that I was actually finding all numbers that weren't prime by my method, haha. So what I'm trying to do now is actually use a for loop to create a list of possible divisors. The problem I am having is finding a way such that it will try all points between the number 2 and the oddNum before printing that it's prime, rather than saying its prime after each individual divisor test. Any idea which way I Should go with this?
If it helps here is my new code: http://dpaste.com/676869/ I know the problem is with the if statement I just can't think of a way to fix it. Is it even changing divisor from 2 at all or is it keeping oddNum steady at 3 for all the tests because that's where it's initialized at the beginning?
"It is set to 998 because 1 and 2 are untested primes, as oddNum is initially set to 3." 1 is not a prime number ^^ You need a loop within a loop; one loop to increment the prime candidates, and one to increment the numbers that you're testing as divisors. You can see my implementation at http://meeplikesheep.wordpress.com/2011/12/23/237/ , but everybody has their own way of coding, and it's more fun to work it out yourself and then compare. Good luck!
Join our real-time social learning platform and learn together with your friends!