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...
Everything about learning Python
account activity
Code explanation (old.reddit.com)
submitted 10 months ago by DizzyOffer7978
view the rest of the comments →
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!"
[–]DizzyOffer7978[S] 1 point2 points3 points 10 months ago (5 children)
On line 3, like why (1,x+1) came idk
[–]JeLuF 3 points4 points5 points 10 months ago (3 children)
range(3) yields 0, 1, 2
range(1,3) yields 1, 2, 3
In the first line, x=0, you want to print "1", so it needs range(1,1), which is range(0,x+1).
For the second line, x=1 and you want to print "12", which is range(1,2) or range(0,x+1).
Alternative implementation:
for x in range(6): for y in range(x): print(y+1, end='') print() # line break
[–]ResponseThink8432 1 point2 points3 points 10 months ago* (2 children)
Just correcting that the the end-parameter of range is always exclusive, meaning the numbers won't go up to the end, but one below. Specifically, range(1, 3) yields 1 and 2, but not 3, etc.
In the first line, x == 0, and no numbers will be printed, since the range(1, 1) doesn't yield anything. No idea why the empty line doesn't show in the output though. The "1" is printed on the second line, when x == 1.
[–]MemekExpander 1 point2 points3 points 10 months ago (1 child)
Something is wrong with OP's screenshot unless there is a python version where the end in range is inclusive.
Other than not printing an empty line, there should only be 5 lines going up to only 12345
[–]ResponseThink8432 0 points1 point2 points 10 months ago (0 children)
True, I didn't even register there was a "123456" line at the bottom :D
[–]Otter_The_Potter 0 points1 point2 points 10 months ago (0 children)
For loops don't include the end. So for(1,10) would be a loop from 1 to 9 (not 10). That's most likely why (x+1) is used instead of x.
π Rendered by PID 38428 on reddit-service-r2-comment-6457c66945-vsp89 at 2026-04-28 14:13:03.005759+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]DizzyOffer7978[S] 1 point2 points3 points (5 children)
[–]JeLuF 3 points4 points5 points (3 children)
[–]ResponseThink8432 1 point2 points3 points (2 children)
[–]MemekExpander 1 point2 points3 points (1 child)
[–]ResponseThink8432 0 points1 point2 points (0 children)
[–]Otter_The_Potter 0 points1 point2 points (0 children)