It's a simple question, Python. One more blank line.

Asked 2 years ago, Updated 2 years ago, 15 views

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

2022-09-20 19:21

1 Answers

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.


2022-09-20 19:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.