Académique Documents
Professionnel Documents
Culture Documents
Chapitre 1 - Structure Algorithmique
Chapitre 1 - Structure Algorithmique
I. Indentation
En python:
d1
d2
d2
if Condition1:
on
on
on
C
C
Séquence1
elif Condition2:
Séquence2
else:
Séquence3
q1
q2
Sé
Sé
def exif(x):
if x < 0:
return 2 * x
return x + 2
else:
return x ** 2
exif(4) = 4**2 = 16
exif(-3)=(-3)*2=-6
exif(1)=3
def exif2(x):
if 0<=x<2:
return 2*x
if 1<=x<3:
return x+1
else:
return x+2
1
fi
fi
def exif3(x):
if 0<=x<2:
y=2*x
if 1<=x<3:
y= x+1
else:
y= x+2
return y
exif3(1)=2
Utilisation du and et du ou
While boolean :
Sequence
Expr
I=1
While I < 11:
print(i)
I+=1
print(‘fini”)
Seq
for I in iterable:
sequence
Init i
Seq
2
ffi
Syntaxe range:
range(n)
For I in range(1,11):
print(I)
3
ffi
fi