找了好久,但是都找不到錯誤QAQ
程式碼:
找了好久,但是都找不到錯誤QAQ
程式碼:
def data(num,c):lst = []for i in range(int(num)):ap = input().split(" ")if len(ap)==int(c):lst.append(ap)else:return "Error"return lst
def count(alist,blist):
clist = []for i in range(len(alist)):#2newList = []ac = len(alist[i])bc = len(blist[0])for k in range(bc):new = 0for j in range(ac):new += int(alist[i][j]) * int(blist[j][k])newList.append(new)clist.append(newList)# print("C矩陣為:",clist)return clist
while True:try:inp = input().split(" ")if inp[1] == inp[2] and (inp[1] and inp[2])!=0:alist = data(inp[0],inp[1])if alist != "Error":blist = data(inp[2],inp[3])if blist !="Error":clist = count(alist,blist)for i in range(len(clist)):for k in clist[i]:print(k,end=" ")print()else:print("Error")breakelse:print("Error")breakcontinueelse:print("Error")breakexcept:print("Error")break
# alist = [[1,2,3],[4,5,6]]# blist = [[3,4],[5,6],[7,8]]
print error 後不要直接 break