2016-12-07 74 views
2

我想創建一個程序,乘以用戶給出的兩個矩陣。我希望用戶輸入第一個矩陣的行,然後我想將每一行保存在字典中,其中字典鍵是行的編號。然而,當我做的raw_input詢問用戶ith行,我得到的錯誤:在Python中乘以矩陣,在raw_input的錯誤

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 

回答

0

你需要轉換n的順序在使用它範圍功能。嘗試改變爲下面的代碼:

n = int(raw_input("Enter number of columns=Number of rows")) 
+0

哦,我還沒有意識到......我想我只是把輸入,而不是raw_input。謝謝 – Diego