A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

what do you guys thin about for this answer for hw1 problem 1

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

    def isprime(startnumber): startnumber*=1.0 for divisor in range(2,int(startnumber/2)+1): if startnumber/divisor==int(startnumber/divisor): return False return True number=0 prime_counter=0 max_count=9001 while(prime_counter<max_count): number=number+1 prime_counter=prime_counter if isprime(number): prime_counter=prime_counter+1 else:prime_counter=prime_counter else:print number

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

    ignore the max count of 9001, just testing larger numbers. it does produce the right answer with correct max count.

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

    here is problem 2 of hw1 from math import * def isprime(startnumber): startnumber*=1.0 for divisor in range(2,int(startnumber*0.5)+1): if startnumber/divisor==int(startnumber/divisor): return False return True rawnumber=input('What number N to consider? ') prime_sum_counter=0 number=0 while(number<rawnumber): number=number+1.0 prime_sum_counter=prime_sum_counter if isprime(number): prime_sum_counter=prime_sum_counter+log(number) else:prime_sum_counter=prime_sum_counter else:print prime_sum_counter print rawnumber print prime_sum_counter/rawnumber

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

    post your code using dpaste.com

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

    problem 2: for this line: for divisor in range(2,int(startnumber*0.5)+1): int(startnumber*0.5) can be expressed as startnumber/2 does this line work? if startnumber/divisor==int(startnumber/divisor) it looks like both sides of the comparison are the same python does integer division - read this and look at the note in the table for the / operator http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex what is the purpose of the second line after your while statement prime_sum_counter=prime_sum_counter please use dpaste.com to post your code. It makes it easier for everyone. goto dpast.com - paste your code in the code block - select python for the syntax - click the paste it button - post the link here, thnx put some print statements in your code and print variable values, comparison/calculation results, accumulator values ... stuff like that. It will help you see what your code is doing.

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

    it works. the purpose of the prime_sum_counter= prime_sum_counter is to not alter the running sum if the number isn't prime.

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

    also the function compares decimal to int so if they are equal it is a valid divisor

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

    sorry - i missed that startnumber is a float

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