-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClist0.tex
37 lines (33 loc) · 1.04 KB
/
Clist0.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
\begin{enumerate}
\item
\begin{verbatim}
nmax = 4
CoeffBin = (nmax + 1)*[0]
#initialisée comme une liste de 0
for n in range(nmax + 1):
CoeffBin[n] = (n+1)*[1]
#sous-liste initialisée comme une liste de 1
for p in range(n-1):
CoeffBin[n][p+1] = CoeffBin[n-1][p+1] + CoeffBin[n-1][p]
print(CoeffBin)
>>>
[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]\end{verbatim}
\item Le coefficient du binôme $\binom{6}{4}=15$ calculé avec le quotient de produits. Un double slash est utilisé pour que le calcul renvoie un entier et non un flottant.
\item Inversion de listes.
\begin{verbatim}lili = [0,1,0,0,0,1]
l = len(lili)
i = 0
j = l-1
while i < j:
lili[i],lili[j] = lili[j],lili[i]
i += 1
j-= 1
print(lili)\end{verbatim}
Elle peut se faire en place (en modifiant l'objet) car une liste est modifiable.\newline
En revanche une chaîne de caractères n'est pas modifiable, il faut un nouvel objet.
\begin{verbatim}str = 'tagada'
rnv = ''
for chacha in str:
rnv = chacha + rnv
print(rnv)\end{verbatim}
\end{enumerate}