python中的矩阵相乘,原始输入错误

2024-09-29 23:19:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个程序,乘以两个矩阵由用户给出。我希望用户输入第一个矩阵的行,然后将每一行保存在字典中,字典键是行的编号。然而,当我输入原始信息询问用户ith行时,我得到了错误:

TypeError: cannot concatenate 'str' and 'int' objects

这是我的密码:

print "this program computes the product of two square matrices with real entries"
n = raw_input("Enter number of columns=Number of rows")
rowsofmatrix1={}
columnsofmatrix2={}
for i in range (1,n+1):
   rowsofmatrix1[i]=raw_input("Enter row number"+str(i)+"of the first matrix as a list")
for j in range (1,n+1):
   columnsofmatrix2[j]=raw_input("Enter column number"+str(j)+"of the second matrix as a list")
print rowsofmatrix1

Tags: ofthe用户innumberforinputraw

热门问题