Today we are going to share a Python program to print an identity matrix. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a Python program to print an identity matrix.
1 2 3 4 5 6 7 8 | n=int(input("Enter a number: ")) for i in range(0,n): for j in range(0,n): if(i==j): print("1",sep=" ",end=" ") else: print("0",sep=" ",end=" ") print() |
Enter a number: 5
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.