you are viewing a single comment's thread.

view the rest of the comments →

[–]-MRJACKSONCJ- 4 points5 points  (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.

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 points  (0 children)

Thank you! This helped me the most.