A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    else: n= n+1 else: s = s+1 else: print s

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I'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.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I need the slap face smiley!! Thank you for your patience.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Also using a pastebin site like dpaste.com can make it easier to see/edit your code to get help.

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    You 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

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.