It's a question about changing the Python printout

Asked 2 years ago, Updated 2 years ago, 18 views

for i in range(0,3) :
    for j in range(0,3) :
       print(a[i][j]+b[i][j], end="")

You are creating an expression that represents matrix addition using a double list.

If you do it like I did, it looks like 246810121416168

For when you go around a cycle of a door, print out only 3 numbers.

I want to know how to change the line, so please. I beg you.

python

2022-09-21 20:11

2 Answers

I understood that you wanted to print out a 3 x 3 array. Then you can print it out like this. If you give " to the end, you won't change the line, so I made you change the line after printing three.

for i in range(0,3) :
    for j in range(0,3) :
        if j == 2:
            seperator="\n"
        else:
            seperator=""
        print("{}{} ".format(i,j), end=seperator)


2022-09-21 20:11

You can write it a little simpler if you print a line that floats after running one line in the first for statement.

a = [[1,2,3],[1,2,3],[1,2,3]]
b = [[1,2,3],[1,2,3],[1,2,3]]

for i in range(0,3) :
    for j in range(0,3) :
       print(a[i][j]+b[i][j], end="")
    print(end='\n')


2022-09-21 20:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.