V Việt Quân New member Sep 20, 2021 #1 What will be the output of the following Python code? Code: a= [1, 2, 3, 4, 5] for i in range(1, 5): a[i-1] = a[i] for i in range(0, 5): print(a[i],end = " ") A. 5 5 1 2 3 B. 5 1 2 3 4 C. 2 3 4 5 1 D. 2 3 4 5 5
What will be the output of the following Python code? Code: a= [1, 2, 3, 4, 5] for i in range(1, 5): a[i-1] = a[i] for i in range(0, 5): print(a[i],end = " ") A. 5 5 1 2 3 B. 5 1 2 3 4 C. 2 3 4 5 1 D. 2 3 4 5 5
L Lò Ngọc New member Sep 20, 2021 #2 Answer: d Explanation: The items having indexes from 1 to 4 are shifted forward by one index due to the first for-loop and the item of index four is printed again because of the second for-loop. Upvote 0 Downvote
Answer: d Explanation: The items having indexes from 1 to 4 are shifted forward by one index due to the first for-loop and the item of index four is printed again because of the second for-loop.