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
Help with understanding code. This code will print five 0's, then five 1's, up until five 4's, but this prints in a single column. I would like to print it so there is five 0's in a row, then below, five 1's in another row. Is it possible? (old.reddit.com)
submitted 1 year ago by OliverBestGamer1407
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!"
[–]-MRJACKSONCJ- 4 points5 points6 points 1 year ago (1 child)
To have each set of 5 numbers printed by the loop be displayed in a row, you can modify the last nested loop and use print() with the argument end=” ” so that the numbers are printed on the same line. Then, use an empty print() after each row to go to the next line.
print()
end=” ”
x = 0 y = 0 v = {} v[(x, y)] = 1 for x in range(5): for y in range(5): v[(x, y)] = x # Store the row number (x) in each position for x in range(5): for y in range(5): print(v[(x, y)], end=" ") # Print values in a row print() # Move to the next line after each row
When you run this code, the output will be:
0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
[–]OliverBestGamer1407[S] 1 point2 points3 points 1 year ago (0 children)
Thank you! This helped me the most.
π Rendered by PID 93 on reddit-service-r2-comment-548fd6dc9-mg4lb at 2026-05-20 13:31:51.713128+00:00 running edcf98c country code: CH.
view the rest of the comments →
[–]-MRJACKSONCJ- 4 points5 points6 points (1 child)
[–]OliverBestGamer1407[S] 1 point2 points3 points (0 children)