anonymous
  • anonymous
Help With Problem 1a initial=1 Denom=3 OddPrime=True PrimeNumber=0 if (Denom/2)*2==Denom: OddPrime=False print 'Number is even.' else: OddPrime=True print 'Number is odd, checking if prime..' if OddPrime==True: while PrimeNumber<1001: for i in range(initial,Denom): if Denom%i==0: OddPrime=False if OddPrime==False: Denom+=2 else: OddPrime=True if OddPrime==True: Denom+=2 PrimeNumber+=1 if PrimeNumber==1000
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 :)
SOLVED
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.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
I dont understand why this isnt working correctly. Please help
anonymous
  • anonymous
Opps. Bottom should look like if PrimeNumber==1000: print Denom
anonymous
  • anonymous
please paste you code on dpaste.com or pastebin.com. it'll help with debugging

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
http://dpaste.com/543250/. There you go, any advice is appreciated
anonymous
  • anonymous
added an extra period at the end of that link. http://dpaste.com/543250/ sorry.
anonymous
  • anonymous
fyi, you can choose the style of the code, so you can select python, and it'll add all the pretty syntax colors
anonymous
  • anonymous
http://dpaste.com/543251/ Even better, thank you
anonymous
  • anonymous
Your 'initial' variable is 1, so any number divided by 1 will have 0 as a remainder. So line 14 will always be true
anonymous
  • anonymous
could i fix that simply by setting 'initial' to 2, or would it be more complicated?
anonymous
  • anonymous
You can, but I think there's other issues too, but that's a start
anonymous
  • anonymous
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.
anonymous
  • anonymous
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?
anonymous
  • anonymous
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
anonymous
  • anonymous
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.
anonymous
  • anonymous
is your indentation on line 20 correct?
anonymous
  • anonymous
i believe so, i think it just got messed up when i pasted it. Heres the revised code: http://dpaste.com/543256/
anonymous
  • anonymous
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.
anonymous
  • anonymous
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?
anonymous
  • anonymous
by the way, don't remove line 14 just yet. You'll see why later.
anonymous
  • anonymous
you'll need to play with the indentations (i.e. where the code is actually called) to get to the solution
anonymous
  • anonymous
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
anonymous
  • anonymous
you're welcome. good luck. post back if you need more help
carlsmith
  • carlsmith
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.
carlsmith
  • carlsmith
I put you up a medal as well stuyboyz, keep up the good work mate.
anonymous
  • anonymous
@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?

Looking for something else?

Not the answer you are looking for? Search for more explanations.