Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #declare a blank list
- a=[]
- for i in range(3):
- b=[] #another blank list
- for j in range(3):
- j=int(input('enter number')) #for column
- b.append(j) #put j value in b for making a list
- a.append(b)
- print("matrix is ------")
- for i in range(3):
- for j in range(3):
- print(a[i][j],end=" ")
- print()
- #initialization of sum for primary and secondary diagonal sum
- sum1=0
- sum2=0
- for i in range(3):
- for j in range(3):
- #algorithm for primary and secondary diagonal sum
- if i==j:
- sum1=sum1+a[i][j]
- if sum1!=sum2:
- boolean=0#denote boolean value as true or false
- else:
- for i in range(3):
- sum_row=0
- sum_column=0
- for j in range(3):
- sum_row=sum_row+a[i][j]#summation of row
- sum_column=sum_column+a[j][i]#summation of column
- if sum_row!=sum1:
- boolean=0
- elif sum_column!=sum1:
- boolean=0
- else:
- boolean=1
- if boolean==1:
- print("matrix is magic square")
- else:
- print("matrix is not magic square")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement