Q:

Python program to get matrix as input from user and print it in different type

belongs to collection: Python Array Programs

0

Matrix in python is a two-dimensional data structure which is an array of arrays.

In python, you can easily create a matrix and access elements of the matrix. Here is a program to illustrate creating a matrix and different methods to print it.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to get matrix as input from user and print it in different type

t=()

rows=int(input("Enter number of Rows of the matrix : "))
cols=int(input("Enter number of columns of the matrix : "))

for i in range(rows):
    c=()
    for j in range(cols):
        v=int(input("Enter Value : "))
        c+=(v,)
    t+=(c,)

print("Method 1")
for i in range(len(t)):
    for j in  range(len(t[i])):
        print(t[i][j],end=' ')
    print()

print("Method 2")
for R in t:
    for C in R:
        print(C,end = ' ')
    print()

print("Method 3 ", end = ' ')
print(t)

Output:

Enter number of Rows of the matrix : 2
Enter number of columns of the matrix : 2
Enter Value : 54
Enter Value : 1
Enter Value : 76
Enter Value : 34
Method 1
54 1 
76 34 
Method 2
54 1 
76 34 
Method 3  ((54, 1), (76, 34))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python program to add two matrices and print the r... >>
<< Python program for matrix operations...