Computer Science
Predict the output of the following code fragments:
for x in range(5):
print (x)
Python
Python Control Flow
13 Likes
Answer
0
1
2
3
4
Working
range(5)
will generate a sequence like this [0, 1, 2, 3, 4]. x will be assigned each of the values from this sequence one by one and that will get printed.
Answered By
4 Likes
Related Questions
Predict the output of the following code fragments:
x = 45 while x < 50 : print (x)
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 p in range(1,10): print (p)
Predict the output of the following code fragments:
for q in range(100, 50, -10): print (q)