CBSE Class 12 Computer Science Question 84 of 105

Python Revision Tour — Question 10

Back to all questions
10
Question

Question 2i

Predict the output of the following code fragments:

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

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.