Question: Question 2. Calculating the sum using the while loop Answer the following questions based on the code in the cell below. a. How many times
Question 2. Calculating the sum using the while loop Answer the following questions based on the code in the cell below. a. How many times is the body of the while loop executed? b. Write out, on paper, the values of n and sum at each step through the loop. c. How, if any, would the output change if we do not indent the last line of the code (i.e., print (sum))? Explain. n = 5
sum = 0
while n > 0 :
sum = sum + n
n = n - 1
print (sum)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
