I am running this code to try to make a block of numbers
grid = [[5, 3, 0, 0, 7, 0, 0, 0, 0],
[6, 0, 0, 1, 9, 5, 0, 0, 0],
[0, 9, 8, 0, 0, 0, 0, 6, 0],
[8, 0, 0, 0, 6, 0, 0, 0, 3],
[4, 0, 0, 8, 0, 3, 0, 0, 1],
[7, 0, 0, 0, 2, 0, 0, 0, 6],
[0, 6, 0, 0, 0, 0, 2, 8, 0],
[0, 0, 0, 4, 1, 9, 0, 0, 5],
[0, 0, 0, 0, 8, 0, 0, 7, 9]]
def print_grid():
for line in grid:
for square in line:
if square == 0:
print(".", end=" ")
else:
print(square, end=" ")
print()
print_grid()
however the output is one long list of numbers running down virtically like this:
5
3
.
.
7
.
.
.
.
6
.
.
1
etc etc
Does anyone know what I might be doing wrong?
Many thanks in advance 🙂
>Solution :
Your final print statement (the empty one) is happening after each square, not after each line. Try unindenting it by one level.