Convert Matrix to upper triangular without using numpy : My code had conveted the matrix to Upper Triangular Matrix but I need to eliminate the space after the last element in a row. My code is

 

    n= int(input())
    matrix=[]
    for i in range(n):
        matrix.append(list(map(int,input().rstrip().split())))
    for i in range(n):
        for j in range(n):
            if(i<j):
                print("0",end=" ")
            
            else:
                print(matrix[i][j],end=" ")
        if(i!=n-1):
          print()
                
Outut:

    Expected Output	   Actual Output
    2 0 0\n            2 0 0 \n 
    5 6 0\n            5 6 0 \n
    7 6 5              7 6 5

