Matrix input in N*N form in Python
Since the number of rows is to be equal to the number of columns, you can simply get the number of columns from the first input and stop taking input when the user enters the same number of rows:

l = []
while not l or len(l) &lt; len(l[0]):
    l.append(list(map(int, input().split())))


so that given an input of:

2 3 4
1 2 3
5 6 7


l would become:

[[2, 3, 4], [1, 2, 3], [5, 6, 7]]