Computer Science, asked by schoudhury400, 5 months ago

A square n×n matrix of integers can be written in Python as a list with n elements, where each element is in turn a list of n integers, representing a row of the matrix. For instance, the matrix

1 2 3
4 5 6
7 8 9
would be represented as [[1,2,3], [4,5,6], [7,8,9]].

Write a function leftrotate(m) that takes a list representation m of a square matrix as input, and returns the matrix obtained by rotating the original matrix counterclockwize by 90 degrees.

Answers

Answered by afsanaatia88
1

Answer:

am starting to code in python. When I was to take two inputs from user with a space between the two inputs my code was like

min, p = input().split(" ")

min=int(min)

p=float(p)

which worked fine. In another such problem I am to take a n*n matrix as user input which I declared as arr=[[0 for i in range(n)] for j in range(n)] printing the arr gives a fine matrix(in a single row though) but I am to replace each element '0'with a user input so I use nested loops as

for i in range(0,n)

for j in range(0,n)

arr[i][j]=input()

this also worked fine but with a press of 'enter' button after each element. In this particular problem the user will input elements in one row at space instead of pressing 'enter' button. I wanted to know how to use split in this case like in first case above, keeping in mind the matrix is n*n where we don't know what is n. I prefer to avoid using numpy being a beginner with python.

Similar questions