Answer to Question #243564 in Python for lastone last

Question #243564

write a python program to replicate this for the n*n matrix

expected output:

enter the matrix and no of tasks: 3 2

intial matrix ([0 0 0] [0 0 0] [0 0 0])

task1: row and column 2 2

[[0 1 0] [1 1 1] [0 1 0]]

['0,0', '0,2', '2,0','2,2'] count 4

task2: row and column 1 1

[[1 1 1] [1 1 1] [1 1 0]]

['2,2'] count:1

Ans:['4','1']


1
Expert's answer
2021-09-28T05:39:10-0400
n , m = input("enter the matrix and no of tasks").split()
n = int(n)
m = int(m)
l1 = [[0 for k in range(n)] for k1 in range(n)]
final_sol = []
for t in range(m):
  row1, col1 = input("task"+str(t+1)+": row and column ").split()
  row1 = int(row1)
  col1 = int(col1)
  for k in range(n):
    for k1 in range(n):
      if (row1== (k+1)) or (col1 ==( k1+1)):
        l1[k][k1] = 1
  empty_list = []
  for k in range(n):
    for k1 in range(n):
      if l1[k][k1] ==0:
        empty_list.append(str(k)+','+str(k1))
  print(l1)
  print(empty_list, " count ",str(len(empty_list)))
  final_sol.append(str(len(empty_list)))
print("Ans:", final_sol)

Sample Input

enter the matrix and no of tasks3 2

task1: row and column 2 2

[[0, 1, 0], [1, 1, 1], [0, 1, 0]]

['0,0', '0,2', '2,0', '2,2'] count 4

task2: row and column 1 1

[[1, 1, 1], [1, 1, 1], [1, 1, 0]]

['2,2'] count 1

Ans: ['4', '1']


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