Answer to Question #217903 in Python for sudheer

Question #217903

n, m = input('n * m ').split()

n, m = int(n), int(m)

M = []

for i in range(n):

  tmp = list(int(el) for el in input().split())

  if len(tmp) != m:

    raise ValueError

  M.append(tmp)

for i in range(n):

  for j in range(m):

    if i == j or i == m-j-1:

      continue

    else:

      M[i][j] = 0

for row in M:

  print(row, sep=' ')


output should not be like this:

[4, 0, 0, 0, 4]

[0, 4, 0, 7, 0]

[0, 0, 8, 0, 0]

[0, 6, 0, 2, 0]

[3, 0, 0, 0, 3]

output should be like this without square brackets and coma:

4 0 0 0 4

0 4 0 7 0

0 0 8 0 0

0 6 0 2 0

3 0 0 0 3


1
Expert's answer
2021-07-17T01:30:39-0400
L = []
for _ in range(0, int(raw_input())):
    user_input = raw_input().split(' ')
    command = user_input.pop(0)
    if len(user_input) > 0:
        if 'insert' == command:
            eval("L.{0}({1}, {2})".format(command, user_input[0], user_input[1]))
        else:
            eval("L.{0}({1})".format(command, user_input[0]))
    elif command == 'print':
        print L
    else:
        eval("L.{0}()".format(command))

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