A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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
anonymous
 5 years ago
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

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I dont understand why this isnt working correctly. Please help

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Opps. Bottom should look like if PrimeNumber==1000: print Denom

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0please paste you code on dpaste.com or pastebin.com. it'll help with debugging

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0http://dpaste.com/543250/. There you go, any advice is appreciated

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0added an extra period at the end of that link. http://dpaste.com/543250/ sorry.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0fyi, you can choose the style of the code, so you can select python, and it'll add all the pretty syntax colors

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0http://dpaste.com/543251/ Even better, thank you

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Your 'initial' variable is 1, so any number divided by 1 will have 0 as a remainder. So line 14 will always be true

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0could i fix that simply by setting 'initial' to 2, or would it be more complicated?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0You can, but I think there's other issues too, but that's a start

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok. 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
 5 years ago
Best ResponseYou've already chosen the best response.0well 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
 5 years ago
Best ResponseYou've already chosen the best response.0I 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
 5 years ago
Best ResponseYou've already chosen the best response.0for 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
 5 years ago
Best ResponseYou've already chosen the best response.0is your indentation on line 20 correct?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0i believe so, i think it just got messed up when i pasted it. Heres the revised code: http://dpaste.com/543256/

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok 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
 5 years ago
Best ResponseYou've already chosen the best response.0You'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
 5 years ago
Best ResponseYou've already chosen the best response.0by the way, don't remove line 14 just yet. You'll see why later.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0you'll need to play with the indentations (i.e. where the code is actually called) to get to the solution

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0alright 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
 5 years ago
Best ResponseYou've already chosen the best response.0you're welcome. good luck. post back if you need more help

carlsmith
 5 years ago
Best ResponseYou've already chosen the best response.0Hi 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
 5 years ago
Best ResponseYou've already chosen the best response.0I put you up a medal as well stuyboyz, keep up the good work mate.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0@carlsmith, I noticed that your prime_suspect.html script returns an overflowerror...when you enter a very large odd number; I was wondering, shouldn't the scripting work for any odd number regardless of its size?
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.