A community for students.
Here's the question you clicked on:
 0 viewing
 2 years ago
current_count=1
x=3
Desired_prime_count=int(raw_input('Pick desired Nth largest Prime Number '))
if Desired_prime_count<1: print( 'Please redue with a positive integer ')
elif Desired_prime_count==1: print (2)
elif Desired_prime_count>1:
while(current_count<Desired_prime_count):
for i in range(2,x):
if x%i==0:x=x+2
else:x=x+2
current_count=current_count+1
print (x2)
So this was my miserable attempt at problem set 1 problem 1 for Fall 2008 for finding prime numbers. 5 hours of self troubleshooting, still can't get it to work. Help
 2 years ago
current_count=1 x=3 Desired_prime_count=int(raw_input('Pick desired Nth largest Prime Number ')) if Desired_prime_count<1: print( 'Please redue with a positive integer ') elif Desired_prime_count==1: print (2) elif Desired_prime_count>1: while(current_count<Desired_prime_count): for i in range(2,x): if x%i==0:x=x+2 else:x=x+2 current_count=current_count+1 print (x2) So this was my miserable attempt at problem set 1 problem 1 for Fall 2008 for finding prime numbers. 5 hours of self troubleshooting, still can't get it to work. Help

This Question is Closed

rsmith6559
 2 years ago
Best ResponseYou've already chosen the best response.0When you're writing any program, you should break the problem down into smaller problems, and then break them down into smaller problems and keep doing this until the problems are so small that basically you're forced to write code. One math thing to remember: if a number isn't prime, ultimately it will be divisible by prime numbers. I think it's referred to as the least multiplier.

andrew.m.higgs
 2 years ago
Best ResponseYou've already chosen the best response.0Also try to put some print statement in here and there to see if the program is doing what you expect. I am sure you will be surprised.

drichmond6021023
 2 years ago
Best ResponseYou've already chosen the best response.1current_count=1 x=3 Desired_prime_count=int(raw_input('Pick desired Nth largest Prime Number ')) if Desired_prime_count<1: print( 'Please redue with a positive integer ') elif Desired_prime_count==1: print (2) elif Desired_prime_count>1: while(current_count<Desired_prime_count): for i in range(2,x): print "in for loop" if x%i==0: x=x+2 print x else: x=x+2 print "else"+str(x) print "out of for loop" current_count=current_count+1 print (x2) #Look about nine posts below at Alban18 for three different solutions to #this problem. #Indeed learning programming is a very humbling process, in my continuing #experience anyway. #first decide that you want to learn how and don't worry about the whiz kids #who can't remember when they were helped, (this is what i tell myself) #let desiredPrimeCount be 3, then in for loop i=2 and x=3(as assigned) so, #3%2 is 1, so skips if body goes to else; x is now 5 currentCount is 2, #leaves for loop, (i'm not sure but i think here 2 is the only number in #range (2,3)) SO in the for again (i=2) x is 5, 5%2 is 1 so skips if body and goes #to else body x becomes 7 and currentCount is now 3; but still in for loop(i=3) #which checks 7%3 is 1 so skips the if body goes to the else body x becomes 9 #currentCount becomes 4, but still in for loop(i=4) with x (the for loop's x) #at value of 5, checks 9%4=1, skips the if body goes to the else body, #x becomes 11; since i is no longer in range we break to the while loop where #current count now 3 having been updated in the for loop, I don't think you #wanted increase the loop count here should probably be on the same indent #level as the while, but currentCount now three we get kicked out of the while #and print 9(112). #if you fix the currentCount indent your range grows faster than your i can #catch it #ctrl c will get you out of an infinite loop at least in idle

shupler
 2 years ago
Best ResponseYou've already chosen the best response.1from math import * primeslist=() logsum=0 current_count=1 x=3 y=0 Desired_prime_count=int(raw_input('Pick desired Nth largest Prime Number ')) if Desired_prime_count<1:print( 'Please redue with a positive integer ') elif Desired_prime_count==1: print 2 print log(2) print log(2)/2 elif Desired_prime_count>1: while(current_count<Desired_prime_count): for i in range(2,x): if x%i!=0:y=y+1 if y==x2: current_count=current_count+1 primeslist=primeslist+(x,) y=0 x=x+2 x=x2 print x for c in primeslist: logsum+=log(int(c)) print logsum+log(2) print (logsum+log(2))/x ok this is what ended up working, drichmond, you were right about my range not getting larger per iteration. had to move it back a bracket for it to work. Also I didn't realize the i was for ever individual integer within the range. (I originally thought it would be a collective whole). a bit sluggish but it works :P
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.