Date: 24.12.2021 Program No:16 Matrix Operation Using Nested List Problem Definition: Aim: Program
Date: 24.12.2021 Program No:16 Matrix Operation Using Nested List Problem Definition: Aim: Program
def leftdiagonal():
sum=0
for i in range(row):
for j in range(column):
if i==j:
sum=sum+arr[i][j]
print("Sum of left diagonal=",sum)
def rightdiagonal():
sum=0
for i in range(row):
for j in range(column):
if i+j== row-1:
sum=sum+arr[i][j]
print("sum of right diagonal=",sum)
def sumofboundary():
sum=0
for i in range(row):
for j in range(column):
if i==0 or i==row-1 or j==0 or j==column-1:
sum=sum+arr[i][j]
print("Sum of boundary=",sum)
def sumofnonboundary():
sum=0
for i in range(row):
for j in range(column):
if i!=0 and i!=row-1 and j!=0 and j!=column-1:
sum=sum+arr[i][j]
print("Sum of boundary=",sum)
ch='y'
while ch=='y':
print("1. sum of left diagonal")
print("2. sum of right diagonal")
print("3. sum of boundary")
print("4. sum of non boundary")
ch=int(input("Enter your choice"))
if ch==1:
leftdiagonal()
elif ch==2:
rightdiagonal()
elif ch==3:
sumofboundary()
elif ch==4:
sumofnonboundary()
else:
print("Wrong choice")
print("Do you want to continue")
ch=input("enter your choice y / n")
OUTPUT
2 Row Element
Enter the element4
Enter the element5
Enter the element6
3 Row Element
Enter the element7
Enter the element8
Enter the element9