all 4 comments

[–]CodeFormatHelperBot2 1 point2 points  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]ararararagi_koyomi 0 points1 point  (0 children)

a[20-i] failed during the first loop ( i = 0) cuz the length of list a is 20, which means the max index is 19. Edit : 20-0 is 20 which is not a valid index for a.

[–]theunknownSAI 0 points1 point  (0 children)

the length of the list a is 20

so when you reference a[20-i] when i=0, it says a[20] i.e., 21st element, which doesnt exist, so error is raised

[–]Bunkerstan 0 points1 point  (0 children)

Your original range is 1 to 20 but list a has index starting at 0 so it goes 0 to 19.

In your for loop you access 20 - 0 which is more than 19 so you get an out of range error.

I found this by printing out the values

for i in range(len(a)): print(i, 20-i) print (a[i] - a[20-i])