Length of a list/array/etc is not a valid index for that object. Because it is 0 indexed you at a minimum need to subtract 1 from the length. Range syntax and usage is valid. Max value of range(n) is n-1.
Yes it does but they are using n as the index for every iteration. I don’t think that’s what is intended but the exception is because of their usage of n.
3
u/earchip94 Aug 17 '25 edited Aug 18 '25
Length of a list/array/etc is not a valid index for that object. Because it is 0 indexed you at a minimum need to subtract 1 from the length. Range syntax and usage is valid. Max value of range(n) is n-1.
Edited for clarity.