Найти - Пользователи
Полная версия: Поменять местами 2 столбца матрицы.
Начало » Python для новичков » Поменять местами 2 столбца матрицы.
1
anotcher
Подскажите как исправить код чтобы все работало
N = int(input())
M = int(input())

mat = [[int(i) for i in input().split()] for _ in range(N)]

m = int(input())
t = int(input())

for i in range(N):
mat[i][m],mat[i][t] = mat[i][t],mat[i][m]

for row in mat:
print(*row)
py.user.next
Всё работает и так.

Добавил сообщения
  
>>> def f():
...     N = int(input('Enter the number of rows: '))
...     M = int(input('Enter the number of columns: '))
...     
...     mat = [[int(i) for i in input('Enter a row: ').split()] for _ in range(N)]
...     
...     m = int(input('Enter the first column number: '))
...     t = int(input('Enter the second column number: '))
...     
...     for i in range(N):
...        mat[i][m],mat[i][t] = mat[i][t],mat[i][m]
...     
...     for row in mat:
...         print(*row)
... 
>>> f()
Enter the number of rows: 3
Enter the number of columns: 4
Enter a row: 1 2 3 4
Enter a row: 5 6 7 8
Enter a row: 4 3 2 1
Enter the first column number: 0
Enter the second column number: 3
4 2 3 1
8 6 7 5
1 3 2 4
>>>
anotcher
py.user.next
Всё работает и так.Добавил сообщения
У меня в pycharme тоже все работает, а автотест на степике и pydroid ошибку выдает. Пришлось чутка исправить и все заработало))
ZerG
anotcher
Мы так драйвера на 98 винде ставили…
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB