CBSE Class 11 Computer Science Question 112 of 161

Flow of Control — Question 21

Back to all questions
21
Question

Question 11g

Predict the output of the following code fragments:

for p in range(1,10):
   print (p)        

Answer

Output
1
2
3
4
5
6
7
8
9
Explanation

range(1,10) will generate a sequence like this [1, 2, 3, 4, 4, 5, 6, 7, 8, 9]. p will be assigned each of the values from this sequence one by one and that will get printed.

Answer