Question 6
What will be printed by the following code snippet?
count = 0
for i in range(1, 10, 2):
for j in range(i, 0, -2):
count += 1
print(count)
i values are 1, 3, 5, 7, 9.
For i=1: j=1 (1 step)
For i=3: j=3,1 (2 steps)
For i=5: j=5,3,1 (3 steps)
For i=7: j=7,5,3,1 (4 steps)
For i=9: $j=9,7,5,3,1 (5 steps)$.
Total count = 1 + 2 + 3 + 4 + 5 = 15.