0% found this document useful (0 votes)
12 views

Matrice2 Py

Uploaded by

Lamiss Ghoul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Matrice2 Py

Uploaded by

Lamiss Ghoul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

27/09/2023 19:37 matrice2.

py

1 from numpy import array


2 from random import randint
3
4 def saisie():
5
6 n=int(input("donner ordre de matrice : "))
7 while not(2< n <10) :
8 n=int(input("donner ordre de matrice : "))
9 return n
10
11 def remplir(t,n) :
12 for i in range(n):
13 for j in range(n):
14 t[i,j]=randint(10,99)
15
16 def affiche1(t,n):
17 s="|"
18 for i in range(n):
19 for j in range(n) :
20 s=s+str(t[i,j])+"|"
21 print(s)
22 s="|"
23 def affiche2(t,n) :
24 s="|"
25
26 for i in range(n):
27 for j in range(n):
28 if i==j :
29 s=s+str(t[i,j])+"|"
30 print(s)
31 for i in range(n):
32 for j in range(n):
33 if i==j :
34 t2[i,j]=str(t[i,j])
35 else :
36 t2[i,j]=" * "
37 def affiche3(t,n):
38 s="|"
39 for i in range(n):
40 s=s+str(t[i,n-i-1])+"|"
41 print(s)
42 for i in range(n) :
43
44 for j in range(n):
45 t3[i,j]= " * "
46 t3[i,n-1-i]=str(t[i,n-1-i])
47
48
49 n=saisie()
50 t=array([[int]*n]*n)
51 t2=array([[str]*n]*n)
file:///C:/Users/jelas/AppData/Roaming/Thonny/temp/thonny_9dvwisle.html 1/2
27/09/2023 19:37 matrice2.py

52 t3=array([[str]*n]*n)
53 remplir(t,n)
54 affiche1(t,n)
55 print("\n")
56 print("____________diagonale_____________________")
57 affiche2(t,n)
58 print("\n")
59 affiche1(t2,n)
60 print("\n")
61 print("_______________diagonal__________________")
62 affiche3(t,n)
63 print("\n")
64 affiche1(t3,n)

file:///C:/Users/jelas/AppData/Roaming/Thonny/temp/thonny_9dvwisle.html 2/2

You might also like