Answer to Question #223692 in Python for Ravi

Question #223692

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.


1
Expert's answer
2021-08-06T04:22:57-0400
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 

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