CBSE Class 12 Computer Science Question 82 of 105

Python Revision Tour — Question 8

Back to all questions
8
Question

Question 2g

Predict the output of the following code fragments:

for z in range(-500, 500, 100):
    print (z)
Answer
Output
-500
-400
-300
-200
-100
0
100
200
300
400
Explanation

range(-500, 500, 100) generates a sequence of numbers from -500 to 400 with each subsequent number incrementing by 100. Each number of this sequence is assigned to z one by one and then z gets printed inside the for loop.