Help With Problem 1a
print 'Number is even.'
print 'Number is odd, checking if prime..'
for i in range(initial,Denom):
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
I dont understand why this isnt working correctly. Please help
Opps. Bottom should look like
please paste you code on dpaste.com or pastebin.com. it'll help with debugging
Not the answer you are looking for? Search for more explanations.
There you go, any advice is appreciated
added an extra period at the end of that link.
fyi, you can choose the style of the code, so you can select python, and it'll add all the pretty syntax colors
Even better, thank you
Your 'initial' variable is 1, so any number divided by 1 will have 0 as a remainder. So line 14 will always be true
could i fix that simply by setting 'initial' to 2, or would it be more complicated?
You can, but I think there's other issues too, but that's a start
ok. let's take a look.
lines 3 to 11, will only be executed once. There's no loop to the beginning for it to be reused. I think you wanted the check to be done for every new Denom.
well the reasoning behind that was i figured that once it was established the number was prime, and if i only added to Denom in intervals of 2, Denom would remain prime and i would not need to check it again. Am i assuming something incorrectly?
I think you just want to check all odd number starting from 3. Don't get odd and prime mixed up here. You can certainly only check the odd number by incrementing by 2
for line 5 to 11 since Denom=3, and doesn't every change in those lines. You can effectively remove them, since OddPrime is guarantee to be true.
is your indentation on line 20 correct?
i believe so, i think it just got messed up when i pasted it.
Heres the revised code:
ok a couple of coding style tips
line 5, is not needed, since OddPrime is already True.
line 10, and 14 are also not needed, because you just sent the condition in the line above to be the same as the condition.
You're almost there. You have all the pieces, and a couple of extra. Just need to remove the extra stuff.
consider what happens when you're in your for loop. Once you find the prime, do you stop or do you continue?
by the way, don't remove line 14 just yet. You'll see why later.
you'll need to play with the indentations (i.e. where the code is actually called) to get to the solution
alright i have to get off the computer now, but il play with that tomorrow and see if i can figure it out. I think i have an idea of what you mean, thanks a ton for your help
you're welcome. good luck. post back if you need more help
Hi ntoooto. I'll attach a couple of scripts for you to have a look through. The first one only checks whether a number's prime or not, the second one defines a function for checking primes, using the code from the first, which it then uses to find the 1000th prime.
I've documented each line, so they're easy to follow.
I put you up a medal as well stuyboyz, keep up the good work mate.
@carlsmith, I noticed that your prime_suspect.html script returns an overflow-error...when you enter a very large odd number; I was wondering, shouldn't the scripting work for any odd number regardless of its size?