Answer to Question #107686 in Python for edgar

Question #107686
c = 1
sum = 0
while (c < 10):
  c = c + 3
  sum = sum + c

print (sum)
1
Expert's answer
2020-04-06T12:08:37-0400

This program finds the sum of numbers: sum = 4 + 7 + 10 and prints it on the screen.

This amount is 21.

Initial values of variables:

c = 1

sum = 0

Then a loop is executed:

while (c <10):

   c = c + 3

   sum = sum + c


The body of the cycle is executed three times.

Two Operators:

 c = c + 3

  sum = sum + c

repeated three times:

1) c = c + 3 (c = 1 + 3, c = 4)

2) sum = sum + c (sum = 0 + 4), sum = 4)


3) c = c + 3 (c = 4 + 3, c = 7)

4) sum = sum + c (sum = 4 + 7), sum = 11)


5) c = c + 3 (c = 7 + 3, c = 10)

6) sum = sum + c (sum = 11 + 10), sum = 21)

At this point, the variable c becomes 10 (c = 10) and we exit the loop (while (c <10)).

The value of the sum sum (number 21) is printed as a result:

print (sum)







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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS