A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
what do you guys thin about for this answer for hw1 problem 1
anonymous
 5 years ago
what do you guys thin about for this answer for hw1 problem 1

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0def 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ignore the max count of 9001, just testing larger numbers. it does produce the right answer with correct max count.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0here 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0post your code using dpaste.com

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0problem 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#numerictypesintfloatlongcomplex 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0it works. the purpose of the prime_sum_counter= prime_sum_counter is to not alter the running sum if the number isn't prime.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0also the function compares decimal to int so if they are equal it is a valid divisor

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0sorry  i missed that startnumber is a float
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.