我一直在网上搜索,我似乎无法找到如何回答我的作业问题。用户应输入矩阵并指示是要添加还是减去矩阵。您应该能够根据需要添加或减少任意数量的矩阵,而无需重新输入先前的解决方案。我是python的初学者,我不知道该怎么做。到目前为止,我所拥有的只是
#Ask the user to input a matrix
print ('Enter your row one by one (pressing enter between each row).
To terminate, enter an empty row.')
M = []
#Allow them to determine dimensions
while True:
r = input ('Next row > ')
if not r.strip (): # Empty input
break
M.append(list(map(int, r.split())))
#Display the matrix
print('M =', M)