79116391

Date: 2024-10-23 05:22:44
Score: 0.5
Natty:
Report link

When you perform this:

A = [1,2,3,4,5]
i = 0
while i < len(A):
    i += 1
    print(A[i]) # A[1], A[2], A[3], A[4], A[5]

A[5] will be out of bound since index start from zero.

This might be what you expect:

A = [1,2,3,4,5]
i = 0
while i < len(A):
    print(A[i]) # A[0], A[1], A[2], A[3], A[4]
    i += 1 # At the end of loop, i is equal to 5 and then exit the while loop.

Here, A[4] is defined, which is 5.

Reasons:
  • Has code block (-0.5):
  • Starts with a question (0.5): When you
  • Low reputation (0.5):
Posted by: Muhammad Ikhwan Perwira