A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
Hello, I am having difficulty editing my solution for ps1a into a solution for ps1b. I had no problem with the ps1a, but this second part has left me completely clueless.. Any help will be appreciated, thanks.
anonymous
 5 years ago
Hello, I am having difficulty editing my solution for ps1a into a solution for ps1b. I had no problem with the ps1a, but this second part has left me completely clueless.. Any help will be appreciated, thanks.

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Here's my code for ps1a:

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0First what you need to do is add the the command import math to the top of your code then add an assignment named sumOfPrimes=0. Under your if true statement add the command sumOfPrimes=sumOfPrimes+math.log(testInteger). Now depending on through what number of primes you want to add you need to change your number in the while loop.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I believe this is how you do it but I did it wrong the first time I did it because I misread the directions and I didn't want to redo it. So if anyone else has any suggestions please answer back.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I added some lines into your script. It should work. If any questions, feel free to ask me. ## Start from here from math import* testInteger = 1 #Number to be tested if prime numberOfPrime = 1 #Number of prime (changes if prime # found) lnproduct=log(2) n=300 while(numberOfPrime<n): #Sets limit, stops when 1000th prime found isPrime = True #assume that the test number is prime for x in range(2,testInteger/2): #if any number between 2 and the number divides evenly if testInteger%x ==0: #Then the number is not prime isPrime = False if isPrime == True: lnproduct=lnproduct+log(testInteger) numberOfPrime = numberOfPrime + 1 #numbers the prime testInteger = testInteger + 2 #submits next number to test if isPrime == False: testInteger = testInteger + 2 #if not prime, tests next number n=testInteger ratio=lnproduct/n print lnproduct print n print ratio

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Thanks, I ran that code and it seemed to work great, plus I understand the logic behind each addition. I appreciate the help!
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.