Answer to Question #2177 in Python for Callie Camper
<br>(a) Write a is_prime(n) function. <br>
It should accept a positive integer n>1 as input, and output True or False, depending on whether n is or is not a prime number. Do this with a loop that checks whether for any integer d, 1 < d < sqrt(n), d divides n.
I'd suggest a while loop -- think carefully about the conditional for the loop, and when you want to change
this conditional inside the loop. (Use a boolean for your condition).
(b) Write a prime_sum(n) function.<br>
It should accept an even number n>1 as input, and via a loop search for primes p & q with p + q = n.
Hint: start with p = 3. If (p) and (n-p) are prime you are done. If not, set p+=2 and try again.
<br>i) Ask the user for an even number n. Continually ask them until they do give you a positive even number. <br>
ii) Search for the summands p & q, and either print them out (if they exist) or say they don't. <br>
iii) Ask the user if they wish to try with another even, and let them continue until they quit.
Need a fast expert's response?Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!