【发布时间】:2022-11-18 02:18:17
【问题描述】:
Rows = int(input("give the number of rows:"))
Columns = int(input("Give the number of columns:"))
matrix = []
for i in range(Rows):
matrix.append(['a', 'b', 'c','d', 'e'])
for vector in matrix:
print(matrix)
这是输出:
give the number of rows:3
Give the number of columns:3
[['a', 'b', 'c', 'd', 'e']]
[['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e']]
[['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e']]
[['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e']]
[['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e']]
[['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e']]
[当用户输入 3x3 的行和列时需要像这样]
【问题讨论】:
-
什么是预期的输出?您是否期待一个 3 项数组,其中项是长度为 3 的向量?
-
您的代码缩进使其无效。
-
抱歉。我对此很陌生。
-
没问题!下面发布了一个似乎可以解决您的问题的提交。