A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

Im on lecture 2 and cannot figure out how to separate odd numbers and prime numbers! I figured out how to generate odd numbers here http://dpaste.com/535600/ How do I get primes out of that?

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

    Is there a specific interval of numbers that you want?

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

    you want to put another loop in between line 6 and line 7 and it should be indented to the same level as line 6. that inner loop needs to test the number to see if it is prime

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

    the new loop will be 'nested' 'inside' the 'outer' loop (the while loop)

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

    How do I test it to see if it is a prime? Do I have to divide it by a number, etc lol im lost

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

    A prime number evenly divides by itself and 1 ONLY. So n/n=1 & n/1=n. Both of these have remainder of 0. If n divided by any integer between 1 and n has a remainder of 0, then n is NOT prime. Use the modulus (%) operation to find if a number has a remainder. Ex. n=15. 15%2=1 (15/2= 7 with remainder of 1). 15%3=0 (15/3= 5 with remainder of 0). So since there is at least 1 divisor (besides 1 & 15), in this case, 3, that returns 0, then 15 is not a prime.

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

    http://openstudy.com/updates/4db29a8764cb8b0b773f606e?source=email#/updates/4db692e6c08f8b0b3ee131c3 Check this question, it covers the same problem, there's a link to some working code that doesn't use imports or lists etc.. You might find what you need in there.

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

    That link doesn't seem to work, should do? Erm, just go to the list of questions and it is currently the one at the very top. The title is grupiyati: help with p1 anyone

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

    http://pastebin.com/KU0CXFx3 There's a solution here if you wanted one.

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

    https://gist.github.com/944461 This might help.

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

    def is_prime(number): if number < 2: return False for each in range(2, (number+2) / 2): if number % each == 0: return False return True tally, n = 0, 0 while tally < 1000: n += 1 if is_prime(n): tally += 1 print n # modified and perfected by cs

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