Structures de contrôle en Python - cpge-paradise.com
Transcript of Structures de contrôle en Python - cpge-paradise.com
![Page 1: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/1.jpg)
Structures de controle en Python
G. Dewaele
4 septembre 2017
Lycee Louis-le-Grand
![Page 2: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/2.jpg)
Structure conditionnelle
expr_bool
True
False
instruction_1
instruction_n
if expr_bool :
instruction_1...
instruction_n...
2
![Page 3: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/3.jpg)
Exemple
if x%2==0 :print("Pair")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair")
3
![Page 4: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/4.jpg)
Exemple
if x%2==0 :print("Pair")
10
23x
x%2==0?x 2==0?x%2==0?
True
False
Print("Pair")
3
![Page 5: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/5.jpg)
Exemple
if x%2==0 :print("Pair")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair")Print("Pair")
3
![Page 6: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/6.jpg)
Exemple
if x%2==0 :print("Pair")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair")
3
![Page 7: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/7.jpg)
Exemple
if x%2==0 :print("Pair")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair")
3
![Page 8: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/8.jpg)
Exemple
if x%2==0 :print("Pair")
10
23x
x%2==0?x 2==0?x%2==0?
True
False
Print("Pair")
3
![Page 9: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/9.jpg)
Exemple
if x%2==0 :print("Pair")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair")
3
![Page 10: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/10.jpg)
Structure conditionelle (2)
expr_bool
True
False
instruction_A_1
instruction_A_n
instruction_B_1
instruction_B_n
if expr_bool :
instruction_A_1...
instruction_A_n
else :instruction_B_1...
instruction_B_n...
4
![Page 11: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/11.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair") Print("Imp.")
5
![Page 12: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/12.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x 2==0?x%2==0?
True
False
Print("Pair") Print("Imp.")
5
![Page 13: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/13.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair")Print("Pair") Print("Imp.")
5
![Page 14: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/14.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair") Print("Imp.")
5
![Page 15: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/15.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair") Print("Imp.")
5
![Page 16: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/16.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x 2==0?x%2==0?
True
False
Print("Pair") Print("Imp.")
5
![Page 17: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/17.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair") Print("Imp.")Print("Imp.")
5
![Page 18: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/18.jpg)
Exemple
if x%2==0 :print("Pair")
else :print("Imp.")
10
23x
x%2==0?x%2==0?
True
False
Print("Pair") Print("Imp.")
5
![Page 19: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/19.jpg)
Multiples chemins avec « elif »
if x==0 :print("Nul")
elif x>=0 :print("Pos.")
else :print("Nég.")
x==0? x>=0?
True True
False False
Print("Nul") Print("Pos.") Print("Nég.")
6
![Page 20: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/20.jpg)
Structure « while »
expr_bool
True
False
instruction_1
instruction_n
while expr_bool :
instruction_1...
instruction_n...
7
![Page 21: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/21.jpg)
Exemple
u<5?
True
False
print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1u
8
![Page 22: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/22.jpg)
Exemple
u<5?u<5?
True
False
print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1u
8
![Page 23: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/23.jpg)
Exemple
u<5?
True
False
print(u)print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1u
8
![Page 24: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/24.jpg)
Exemple
u<5?
True
False
print(u)
u = 2*uu = 2*u
while u<5 :print(u)
u = 2*u
1u
8
![Page 25: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/25.jpg)
Exemple
u<5?u<5?
True
False
print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1
2u
8
![Page 26: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/26.jpg)
Exemple
u<5?
True
False
print(u)print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1
2u
8
![Page 27: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/27.jpg)
Exemple
u<5?
True
False
print(u)
u = 2*uu = 2*u
while u<5 :print(u)
u = 2*u
1
2u
8
![Page 28: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/28.jpg)
Exemple
u<5?u<5?
True
False
print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1
2
4
u
8
![Page 29: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/29.jpg)
Exemple
u<5?
True
False
print(u)print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1
2
4
u
8
![Page 30: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/30.jpg)
Exemple
u<5?
True
False
print(u)
u = 2*uu = 2*u
while u<5 :print(u)
u = 2*u
1
2
4
u
8
![Page 31: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/31.jpg)
Exemple
u<5?u<5?
True
False
print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1
2
4
8
u
8
![Page 32: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/32.jpg)
Exemple
u<5?
True
False
print(u)
u = 2*u
while u<5 :print(u)
u = 2*u
1
2
4
8
u
8
![Page 33: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/33.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?
True
False
a,b = b,a%ba,b = b,a%b print(a)
while b>0 :a,b = b,a%b
print(a)
420
126a
b
9
![Page 34: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/34.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?b>0?
True
False
a,b = b,a%ba,b = b,a%b print(a)
while b>0 :a,b = b,a%b
print(a)
420
126a
b
9
![Page 35: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/35.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?
True
False
a,b = b,a%ba,b = b,a ba,b = b,a%b print(a)
while b>0 :a,b = b,a%b
print(a)
420
126a
b
9
![Page 36: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/36.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?b>0?
True
False
a,b = b,a%ba,b = b,a%b print(a)
while b>0 :a,b = b,a%b
print(a)
420
126
42
a
b
9
![Page 37: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/37.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?
True
False
a,b = b,a%ba,b = b,a ba,b = b,a%b print(a)
while b>0 :a,b = b,a%b
print(a)
420
126
42
a
b
9
![Page 38: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/38.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?b>0?
True
False
a,b = b,a%ba,b = b,a%b print(a)
while b>0 :a,b = b,a%b
print(a)
420
126
42
0
a
b
9
![Page 39: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/39.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?
True
False
a,b = b,a%ba,b = b,a%b print(a)print(a)
while b>0 :a,b = b,a%b
print(a)
420
126
42
0
a
b
9
![Page 40: Structures de contrôle en Python - cpge-paradise.com](https://reader036.fdocuments.us/reader036/viewer/2022062420/62ae9e048f2138134f17847d/html5/thumbnails/40.jpg)
Calcul du PGCD avec l’algorithme d’Euclide
b>0?
True
False
a,b = b,a%ba,b = b,a%b print(a)
while b>0 :a,b = b,a%b
print(a)
420
126
42
0
a
b
9