Enter the two numbers corresponding to the x and y coordinates with one space.
In the corresponding coordinates of the 5x5 compartments, The rest outputs zero.
The code is as follows.
n = int(input())
white = []
for i in range(n):
a, b = list(map(int, input().split(" ")))
white.append([a, b])
for x in range(1, 6):
for y in range(1, 6):
if [x, y] in white:
print(1, end=" ")
else:
print(0, end = " ")
print("\n")
If you enter and execute 5 coordinates, you will see the following.
5
1 1
2 2
3 3
4 4
5 5
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
I want to remove the space and print it out as follows.
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
What should I do?
python
print()
This will automatically add a blank line.
print("\n")
In this way, you take a line change and add an empty line to make two line changes.
Therefore, replacing print("\n")
with print()
resolves the problem.
© 2024 OneMinuteCode. All rights reserved.