Answer to Question #190332 in Python for python

Question #190332

Write a function that takes a 2D list(matrix) of 3x3 and ask user to input the values


1
Expert's answer
2021-05-07T05:01:33-0400
def input_values(matrix):


	for i in range(len(matrix)):
		k = 0
		while k < len(matrix[i]):
			tmp = input('M[{}][{}] = '.format(i+1,k+1))
			try:
				matrix[i][k] = int(tmp)
				k += 1
			except ValueError:
				print('incorrect input')
				continue
	return matrix

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS