Given
rows = 4
cols = 3
matrix = 1 2 3
4 5 6
7 8 9
10 11 12
output : 1 2 3 6 5 4 7 8 9 12 11 10
Explination : Every alternative row should be in reverse order.
row = int(input("rows = "))
col = int(input("cols = "))
print("matrix = ")
l = []
foo = 1
for i in range(row):
s = list(map(int, input().split()))
if foo%2==0: s.reverse()
l.append(s)
foo+=1
for i in l:
print(*i, end=" ")
print()
Example:
rows = 4
cols = 3
matrix =
1 2 3
4 5 6
7 8 9
10 11 12
Output:
1 2 3 6 5 4 7 8 9 12 11 10
Comments
Leave a comment