# Initiation à la programmation ENSAE 1A

## ecrit_2007_rattrapage.tex

File: ecrit_2007_rattrapage.tex, line 32

```
l2 = [ ( l [i], i ) for i in range (0, len (l)) ]
l2.sort ()
print l2 [0][1]  # affiche la position du plus petit élément
# dans le tableau initial

```

File: ecrit_2007_rattrapage.tex, line 50

```
def ensemble_lettre (s) :
ens = []
for i in range (0, len (s)) :
c = s [i]
if c in ens :
ens.append (c)
return ens

print lettre ("baaa")

```

File: ecrit_2007_rattrapage.tex, line 75

```
def ensemble_lettre (s) :
ens = []
for i in range (0, len (s)) :
c = s [i]
if c not in ens :
ens.append (c)
return ens

```

File: ecrit_2007_rattrapage.tex, line 98

```
def autre_parcours (n) :
i = 0
j = 0
k = 0

while k < n :
print (k,i,j)
if i == 0 and j == 0 :
k += 1
if j == 0 and i < k :
i += 1
elif i == k and j < k :
j += 1
elif j == k and i > 0 :
i -= 1
elif i == 0 and j > 0 :
j -= 1

autre_parcours (3)

```

File: ecrit_2007_rattrapage.tex, line 127

```
(0, 0, 0)
(1, 1, 0)
(1, 1, 1)
(1, 0, 1)
(1, 0, 0)
(2, 1, 0)
(2, 2, 0)
(2, 2, 1)
(2, 2, 2)
(2, 1, 2)
(2, 0, 2)
(2, 0, 1)
(2, 0, 0)

```

File: ecrit_2007_rattrapage.tex, line 165

```
k = [10,14,15,-1,6]
l = []
for i in range (0,len (k)) :
l.append ( k [ len (k) - i ] )

```

File: ecrit_2007_rattrapage.tex, line 180

```
k = [10,14,15,-1,6]
l = []
for i in range (0,len (k)) :
l.append ( k [ len (k) - i-1 ] )  # -1 a été ajouté

```

File: ecrit_2007_rattrapage.tex, line 203

```
def puiss (x, n) :
s = 1.0
for i in range (0,n) :
s *= x
return s

def log_suite (x) :
x    = float (x-1)
# ......
s    = 0
old  = -1
n    = 1
while abs (old - s) > 1e-10 :
old = s
po  = puiss (x,n) / n
if n % 2 == 0 : po = -po
s  += po
n  += 1
# ......
return s

print log_suite (2)

```

File: ecrit_2007_rattrapage.tex, line 231

```
# ......
# ......
# ......
# ......
# ......
# ......
def log_suite (x) :
x    = float (x-1)
x0   = x
s    = 0
old  = -1
n    = 1
while abs (old - s) > 1e-10 :
old = s
po  = x / n
if n % 2 == 0 : po = -po
s  += po
n  += 1
x  *= x0
return s

print log_suite (2)

```

File: ecrit_2007_rattrapage.tex, line 269

```
def racine_carree (k) :
x0 = float (k)+1
x  = float (k)
while abs (x-x0) > 1e-10 :
x0 = x
x  = (k-x*x) / (2 * x) + x
return x

```

File: ecrit_2007_rattrapage.tex, line 339

```
class Noeud :
def __init__ (self, mot) :
self.mot = mot
self.avant = None
self.apres = None
def insere (self, mot) :
if mot < self.mot :
if self.avant == None : self.avant = Noeud (mot)
else : self.avant.insere (mot)
else :
if self.apres == None : self.apres = Noeud (mot)
else : self.apres.insere (mot)
def affiche (self) :
if self.avant != None : self.avant.affiche ()
print self.mot
if self.apres != None : self.apres.affiche ()

li = ["premier","deuxième","troisième","quatrième", \
"cinquième","sixième","centième","mystère"]
r = None
for m in li :
if r == None : r = Noeud (m)
else : r.insere (m)
r.affiche ()

```

File: ecrit_2007_rattrapage.tex, line 372

```
centième
cinquième
deuxième
mystère
premier
quatrième
sixième
troisième

```