Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class Matrice:
- def __init__(self):
- self.__body=[]
- def MatriceInitL( self,L):
- n=int(math.sqrt(len(L)))
- for i in range(n):
- x=[]
- for j in range(n):
- x.append(L[i*n+j])
- self.__body.append(x)
- def MatricePrintS(self):
- n=len(self.__body)
- print("[")
- for il in range (n):
- print(" [")
- for iC in range (n):
- print(" ",self.__body[il][iC],", ", end =" ")
- if il<n-1:
- print(" ],")
- else:
- print(" ]")
- print("]")
- def MatriceDim(self):
- return len(self.__body[0])
- def MatriceModifier(self, i, j, v):
- self.__body[i][j]=v
- def MatriceValue(self,i,j):
- return self.__body[i][j]
- L=eval(input("L="))
- #L=[1,2,3,1,2,3,1,2,3,1,0,1,1,1,0,1,1,1,4,2,4,4,2,4,4]
- def MatriceListe(L):
- M=Matrice()#M est du type Matrice
- M.MatriceInitL(L)#On initialise M grace a L
- M.MatricePrintS()#On affiche M
- return M
- M=MatriceListe(L)#On stocke la matrice sous la variable M, pour l utiliser apres
- def SommeProduit(M):
- n=M.MatriceDim()
- L=[]
- S=0
- P=1
- for i in range (n):
- for j in range (n):
- if i==n-j-1:
- L.append (M.MatriceValue(i,j))
- S=S+L[i]
- P=P*L[i]
- return ("Somme=", S,"Produit=", P)
- print (SommeProduit(M))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement