A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 4 years ago
So I have a question about the prime question in problem set 1. Im trying to approach the question as a list problem. I already learned to test for primes in my code but Im having difficult asking for the 1000th term since pyscritpter keeps crashing, I think there is something wrong with my while loop...
def search_primes(n):
#I start by having an empty list
terms=[]
#Then we assigned i the value of 0 because we want to start counting.
i = 0
#the loop would stop as soon as i is equal to n
while i<=n:
# My condition is that in order to append to the list the num
anonymous
 4 years ago
So I have a question about the prime question in problem set 1. Im trying to approach the question as a list problem. I already learned to test for primes in my code but Im having difficult asking for the 1000th term since pyscritpter keeps crashing, I think there is something wrong with my while loop... def search_primes(n): #I start by having an empty list terms=[] #Then we assigned i the value of 0 because we want to start counting. i = 0 #the loop would stop as soon as i is equal to n while i<=n: # My condition is that in order to append to the list the num

This Question is Closed

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0def search_primes(n): #I start by having an empty list terms=[] #Then we assigned i the value of 0 because we want to start counting. i = 0 #the loop would stop as soon as i is equal to n while i<=n: # My condition is that in order to append to the list the number should # pass the Prime_Test which already has 0,1, and 2 in consideration. if Prime_Test(i) is True: #Here is the new assigned value of i gets added to the list terms.append(i) #just to make sure the list keeps going up i = i + 1 #We're interested on the final value of the terms return terms[n]

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Your logic is sound but I think I see where the problem occurs. Let's go over your steps in pseudocode. # first you initialize a set of variables # terms is a list [] that will store your list of primes as you find them # n is the nth prime that you are looking for; in this case, it will be 1000 but you are writing as a function so you can generalize # i is the particular number you are testing for primality ### a problem that i see is that you are missing a variable that's keeping track of which prime number your are at; you will need to define a variable such as count # you then setup a while loop to cycle through the integers until you have find the 1000th prime. so your while loop needs to look like this: while count<=n: not while i<n: you will increase count by 1 when i is a prime. i is the number you are testing for primality. count is the count you are on in terms of your search for the nth prime. Hope that helps.
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.