Python二维数组的应用

横向输出二维数组(我也不知道是不是这样叫QAQ)

1
2
3
4
5
6
7
8
9
10
11
12
b=[]
while True:
a=list(map(int,input("vs:").split()))
if len(a)==0:
break
b.append(a)
print(b)
##input:1 3 5
## 2 4 6
## 8 0 8
## (回车)
##output:[[1,3,5],[2,4,6],[8,0,8]]

按行输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
b=[]
while True:
a=list(map(int,input("vs:").split()))
if len(a)==0:
break
b.append(a)
for row in range(len(b)):
print(b[row])
##input:1 3 5
## 2 4 6
## 8 0 8
## (回车)
##output:[1,3,5]
## [2,4,6]
## [8,0,8]

按列输出

1
2
3
4
5
6
7
8
9
10
##按列输出: 1 2 3
## 4 5 6

for col in range(3):
for row in range(2):
print(b[col][row],end=' ')
print()
##output:1 4
## 2 5
## 3 6

输出行列的3种方法

First

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
b=[]
while True:
a=list(map(int,input().split()))
if len(a)==0:
break
b.append(a)
for eld in b:
for e in eld:
print(e,end=' ')
print()
##input:1 3 5
## 2 4 6
## 8 0 8
## (回车)
##output:1 3 5
## 2 4 6
## 8 0 8

Second

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
b=[]
while True:
a=list(map(int,input().split()))
if len(a)==0:
break
b.append(a)
for row in range(len(b)):
for e in b[row]:
print(e,end=' ')
print()
##input:1 3 5
## 2 4 6
## 8 0 8
## (回车)
##output:1 3 5
## 2 4 6
## 8 0 8

Third

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
b=[]
while True:
a=list(map(int,input().split()))
if len(a)==0:
break
b.append(a)
for row in range(len(b)):
for i in range(len(b[row])):
print(b[row][i],end=' ')
print()
##input:1 3 5
## 2 4 6
## 8 0 8
## (回车)
##output:1 3 5
## 2 4 6
## 8 0 8

input和output的输出格式有一点点问题,后续会更正,它们正确的看法应该是对齐的~