我想创建一个程序,乘以两个矩阵由用户给出。我希望用户输入第一个矩阵的行,然后将每一行保存在字典中,字典键是行的编号。然而,当我输入原始信息询问用户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
为了在range函数中使用n,需要转换n。尝试更改为以下代码:
相关问题 更多 >
编程相关推荐