48,552 views
28 votes
28 votes
C = 1 sum = 0 while (c < 10): c = c + 2 sum = sum + c print (sum)

User Watbywbarif
by
2.5k points

2 Answers

10 votes
10 votes


\huge \boxed{\sf 35}

c = 1, sum = 0

(The loop runs)

1 < 10, c = 1 + 2, sum = 0 + 3

c = 3, sum = 3

3 > 10, c = 3 + 2, sum = 3 + 5

c = 5, sum = 8

5 > 10, c = 5 + 2, sum = 8 + 7

c = 7, sum = 15

7 > 10, c = 7 + 2, sum = 15 + 9

c = 9, sum = 24

9 > 10, c = 9 + 2, sum = 24 + 11

c = 11, sum = 35

(The condition is false and the loop ends)

11 > 10, print sum

User Jose Ananio
by
3.2k points
25 votes
25 votes

Answer:

35

Step-by-step explanation:

The loop runs 5 times with the following values of c: 1,3,5,7,9 at the start of the iteration, and 2 higher at the end. So the values that get added to sum are: 3,5,7,9,11, hence sum = 3+5+7+9+11 = 35.

Always look carefully at the last iteration of a loop. At the last iteration, when c equals 9, it is still valid to make another iteration. However, 11 gets added to the sum.

User Bill Cheatham
by
2.5k points