PYTHON for BEGINNERS. Need help with fixing this wrong code. Thank you. Assume t
ID: 3795800 • Letter: P
Question
PYTHON for BEGINNERS. Need help with fixing this wrong code. Thank you.
Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the statements needed to compute the sum of the first n prime numbers. The sum should be associated with the variable total. Note: is_prime takes an integer as a parameter and returns True if and only if that integer is prime.
---------------------------------
n >0
total =0
while total <= n:
if is_prime(n):
total = total+ n
if total <= n:
total = n
n = n + 1
Explanation / Answer
n >0
total =0
i=1 #variable to run the loop till n
while i <= n:
if is_prime(i):
total = total+ i
i=i+1
else
i=i+1
#note:please ask in case of any doubt
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.