KnowledgeBoat Logo

Computer Science

Predict the output of the following code fragments:

c = 0
for x in range(10): 
    for y in range(5):
        c += 1
print (c)

Python

Python Control Flow

28 Likes

Answer

50

Working

Outer loop executes 10 times. For each iteration of outer loop, inner loop executes 5 times. Thus, the statement c += 1 is executed 10 * 5 = 50 times. c is incremented by 1 in each execution so final value of c becomes 50.

Answered By

13 Likes


Related Questions