What will be the output of the following code?i = 3for i in range (4) print (i)
Question
What will be the output of the following code?
i = 3
for i in range (4):
print (i)
Solution
The output of the code will be:
0 1 2 3
Explanation: The code is written in Python. The 'for' loop is used to iterate over a sequence of numbers generated by the 'range' function. In this case, the range is 4, so it generates numbers from 0 to 3. The variable 'i' is used to hold the current value in each iteration of the loop. The 'print' function is used to output the value of 'i' in each iteration. So, it prints the numbers 0, 1, 2, and 3, each on a new line.
Similar Questions
What will be the output of the following code?i = 3for i in range (4) print (i)
What will be the output of the following code?i = 3for i in range (4) print (i) 0 1 2 3 1 2 3 4 3 4 5 6 3 2 1 0
What is the output of the following code? for i in range(3): print(i) else: print("Loop finished")
What will be printed by the following code?for i in range(5): for j in range(5, 0, -1): if i == j: print(i, end=" ")1 2 3 44 3 2 1 004
What is the output of the following Python code?for i in range(5,0,-1): print(i)5 4 3 2 11 2 3 4 55 5 5 5 51 1 1 1 1
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.