Computer Science
Predict the output of the following code fragments:
for p in range(1,10):
print (p)
Python
Python Control Flow
10 Likes
Answer
1
2
3
4
5
6
7
8
9
Working
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.
Answered By
6 Likes
Related Questions
Predict the output of the following code fragments:
for x in [1,2,3,4,5]: print (x)
Predict the output of the following code fragments:
for x in range(5): print (x)
Predict the output of the following code fragments:
for q in range(100, 50, -10): print (q)
Predict the output of the following code fragments:
for z in range(-500, 500, 100): print (z)