Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import math
  2. class Matrice:
  3. def __init__(self):
  4. self.__body=[]
  5.  
  6. def MatriceInitL( self,L):
  7. n=int(math.sqrt(len(L)))
  8. for i in range(n):
  9. x=[]
  10. for j in range(n):
  11. x.append(L[i*n+j])
  12. self.__body.append(x)
  13.  
  14. def MatricePrintS(self):
  15. n=len(self.__body)
  16. print("[")
  17. for il in range (n):
  18. print(" [")
  19. for iC in range (n):
  20. print(" ",self.__body[il][iC],", ", end =" ")
  21. if il<n-1:
  22. print(" ],")
  23. else:
  24. print(" ]")
  25. print("]")
  26.  
  27. def MatriceDim(self):
  28. return len(self.__body[0])
  29.  
  30. def MatriceModifier(self, i, j, v):
  31. self.__body[i][j]=v
  32.  
  33. def MatriceValue(self,i,j):
  34. return self.__body[i][j]
  35.  
  36. L=eval(input("L="))
  37. #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]
  38. def MatriceListe(L):
  39. M=Matrice()#M est du type Matrice
  40. M.MatriceInitL(L)#On initialise M grace a L
  41. M.MatricePrintS()#On affiche M
  42. return M
  43.  
  44. M=MatriceListe(L)#On stocke la matrice sous la variable M, pour l utiliser apres
  45.  
  46. def SommeProduit(M):
  47. n=M.MatriceDim()
  48. L=[]
  49. S=0
  50. P=1
  51. for i in range (n):
  52. for j in range (n):
  53. if i==n-j-1:
  54. L.append (M.MatriceValue(i,j))
  55. S=S+L[i]
  56. P=P*L[i]
  57. return ("Somme=", S,"Produit=", P)
  58.  
  59.  
  60. print (SommeProduit(M))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement