Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

michalmichalski Group Title

Hi all, Im new to programming and just finished assignment 1.1 (which I think is correct). Could someone tell me if there's room for improvement or what could be done better. thanks heres the code: http://codepad.org/45TEO6yE (it only runs the first 20 primes to save time)

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. duikboot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I think it's very nice, but, maybe you could change n%x == 0 to n % x == 0 which improves readability. It's part of the python style guide: http://www.python.org/dev/peps/pep-0008/

    • 2 years ago
  2. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    it works great, it will find primes less than 10000. If your search criteria was different or changing you would have to guess what the limit would be in line 2, or know the answer b4 hand. could you rewrite it to find just the 2000th prime? without having to guess how big that number is?

    • 2 years ago
  3. duikboot Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Something like this? http://codepad.org/J67EOiDK

    • 2 years ago
  4. Tomas.A Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    you find only prime which is highest in up to 2000 but not 2000th prime

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

    @Tomas.A ah, I misread the question.

    • 2 years ago
  6. michalmichalski Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    cool. thanks all!

    • 2 years ago
  7. carlsmith Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I liked this line. for n in range(3, 10000, 2): Using the optional, third arg like that saved you filtering out all the evens afterwards. It was clever to spot that.

    • 2 years ago
  8. Tomas.A Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @michalmichalski did you manage to write program like @bwCa said?

    • 2 years ago
  9. erthbound0 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    question guys...for this formula, line of for X in range (3,n), i made it: for x in range(3, int(sqrt(n))+1: is this a faster way to run the program

    • 2 years ago
  10. strobe Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    My recommendation would be to try and make this program more useful. Try and make it into a function that has input n and output of the nth prime.

    • 2 years ago
  11. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ... yep you only really have to check up to the square root - but that's just an optimization

    • 2 years ago
  12. michalmichalski Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @ Tomas, no I didnt write it yet - but I ll give it a try. @ earthbound() - good suggestion with the sqrt, thnks thanks for yr comments!

    • 2 years ago
    • Attachments:

See more questions >>>

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.