(ps1b) My program seems to be stuck in an infinite loop, but I'm not sure how this is happening. Code: http://dpaste.com/533437/

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your **free** account and access **expert** answers to this

and **thousands** of other questions.

- anonymous

- schrodinger

I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your **free** account and access **expert** answers to this

and **thousands** of other questions

- Shriram

what input does it give you an infinite loop?

- anonymous

You're asking for input from the user with raw_input(), which returns a string rather than an integer.

- anonymous

Yeah, change line 7 to n = int(raw_input()) and it should be fixed
But I'm pretty sure there's also a logical error... How are you checking whether primeCandidate is actually prime?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

## More answers

- anonymous

If the number is divisible by a whole number then the number is not added to the sum and primeCandidate is incremented. If the divisor is greater than half of primeCandidate, that means that no whole number evenly divides into it, making it prime. There does still seem to be a problem with my program logically, so please let me know if see a problem in that logic. Right now my ratio converges to zero instead of one. Thanks.

- anonymous

You're taking the log of the sum rather than the sum of the logs.
Also, you're missing 3 from your prime numbers. You can fix that by initiating primeSum with log(2) + log(3) at the beginning.

- anonymous

You're also missing the last prime number when the input is prime. For example, when I enter a prime number 7919, that number doesn't get added in.

- anonymous

one way to make your program faster at least is to skip all even numbers since no even numbers past 2 are prime. thatll cut the amount of numbers processed in half. another suggestion would be to write a separate function to detect if the number is prime or not something like
def isPrime(a):
i = 0
while (i

- anonymous

Thanks so much for the help everyone!

Looking for something else?

Not the answer you are looking for? Search for more explanations.