A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
Just joined no experience before so this exercise is doing my head in. Here is what I have and it just loops. Any help would be greatly appreciated.
n=int (1) ##This will act as counter
s=int (3) ## A number to get us started
divs=int (2) ## Integers I will diving with.
while n<5: ## to ensure I kill at 1000th prime
while s%2 != 0: ## If its an even number it isnt prime
while divs<s: ## make sure devisors remain below value
while s%divs==0: ## test to see if prime
divs= divs +1 ## add one to divisor
else: n = n +1
else: n= n+1
el
anonymous
 5 years ago
Just joined no experience before so this exercise is doing my head in. Here is what I have and it just loops. Any help would be greatly appreciated. n=int (1) ##This will act as counter s=int (3) ## A number to get us started divs=int (2) ## Integers I will diving with. while n<5: ## to ensure I kill at 1000th prime while s%2 != 0: ## If its an even number it isnt prime while divs<s: ## make sure devisors remain below value while s%divs==0: ## test to see if prime divs= divs +1 ## add one to divisor else: n = n +1 else: n= n+1 el

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0else: n= n+1 else: s = s+1 else: print s

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I'm not sure I understand what you're trying to do with the while ... else ... bits. I very rarely find a use case for while else, and in your specific case, I don't see how the innermost while loop will end since 3%n for every N in the natural numbers will never = 0. Try restricting yourself to only using else for if statements, and I think you'll have an easier time wrapping your brain around the task.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I need the slap face smiley!! Thank you for your patience.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Also using a pastebin site like dpaste.com can make it easier to see/edit your code to get help.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0You might want to also limit the numerator to odd numbers, and the divisors to a certain value less than the numerator, otherwise it will do the calculation up to the numerator 1, which is not needed. See this website for a good explanation. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
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.