Dremendo Tag Line

Input numbers in nested list and print the largest number in each row in Python

Lists - Question 14

In this question, we will see how to input numbers in a 3X3 integer matrix (nested list) and print the largest number in each row in Python programming. To know more about lists click on the lists lesson.

Q14) Write a program in Python to input numbers in a 3X3 integer matrix (nested list) and print the largest number in each row.

Program

a=[[],[],[]]
r=0;c=0;lg=0;x=0;

print('Enter 9 numbers')
for r in range(3):
    for c in range(3):
        a[r].append(int(input()))


for r in range(3):
    x=0
    for c in range(3):
        print(a[r][c],end=' ')
        if x==0:
            lg=a[r][c]
            x=1
        elif a[r][c]>lg:
            lg=a[r][c]
    print('  Largest Number =',lg)

Output

Enter 9 numbers
18
12
5
10
15
45
38
72
64
18 12 5   Largest Number = 18
10 15 45   Largest Number = 45
38 72 64   Largest Number = 72
video-poster