CBSE Class 12 Computer Science Question 91 of 105

Python Revision Tour — Question 17

Back to all questions
17
Question

Question 4(i)

How many times will the following for loop execute and what's the output?

for i in range(-1, 7, -2):
    for j in range (3):
        print(1, j)
Answer

The loops execute 0 times and the code produces no output. range(-1, 7, -2) returns an empty sequence as there are no numbers that start at -1 and go till 6 decrementing by -2. Due to empty sequence, the loops don't execute.