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

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.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

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

MIT 6.00 Intro Computer Science (OCW)
See more answers at brainly.com
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

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 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]
Your logic is sound but I think I see where the problem occurs. Let's go over your steps in pseudo-code. # 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

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question