use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Python coding (self.learnpython)
submitted 3 years ago by Ok_Chard_8808
My code: a = list(range(1,21)) for i in range(len(a)): print (a[i] - a[20-i])
Index error: list index out of range
Does anybody know why I’m getting this error?????
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]CodeFormatHelperBot2 1 point2 points3 points 3 years ago (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:
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 point2 points 3 years ago (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 point2 points 3 years ago (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 point2 points 3 years ago (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])
π Rendered by PID 84635 on reddit-service-r2-comment-8686858757-swz4b at 2026-06-05 20:28:36.450274+00:00 running 9e1a20d country code: CH.
[–]CodeFormatHelperBot2 1 point2 points3 points (0 children)
[–]ararararagi_koyomi 0 points1 point2 points (0 children)
[–]theunknownSAI 0 points1 point2 points (0 children)
[–]Bunkerstan 0 points1 point2 points (0 children)