211k views
5 votes
I need help with this question!

I need help with this question!-example-1
User MikeD
by
4.4k points

1 Answer

1 vote

Answer:

5 and 10

Step-by-step explanation:

Given

The above code segment

Required

Determine the outputs

Analysing the code segment line by line

[This initialises c to 0]

c = 0

[The following iteration is repeated as long as c is less than 10]

while (c < 10):

[This increments c by 5]. Recall that c is initially 0. Hence, c becomes 0 + 5 = 5

c = c + 5

[This prints the value of c which is 5]

print(c)

The iteration is then repeated because the condition is still true i.e. 5 is less than 10

c = c + 5 = 5 + 5 = 10

[This prints the value of c which is 10]

print(c)

The iteration won't be repeated because the condition is now false i.e. 10 is not less than 10.

Hence, the output is 5 and 10.

User Denis Matafonov
by
5.3k points