A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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.

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

    Here's my code for ps1a:

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

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

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

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

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

    I 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

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

    Thanks, I ran that code and it seemed to work great, plus I understand the logic behind each addition. I appreciate the help!

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