# Initiation à la programmation ENSAE 1A

## ecrit_2009_rattrapage.tex

File: ecrit_2009_rattrapage.tex, line 42

```
def numero_simple (nbimpair, nbpair) :
im = [..... for i in range (1, nbimpair+1) ]
pa = [..... for i in range (1, nbpair  +1) ]
return im,pa

```

File: ecrit_2009_rattrapage.tex, line 51

```
def numerotation (longueur, debut, moy) :
res = []
for li in range (0, len (longueur)) :
if len (res) == 0 : x1 = debut
else :              x1 = res [-1][1]+2

nb = longueur [li] / moy                  # c'est une division entière
# ligne importante
# pour la dernière question
x2 = x1 + nb*2
res.append ( (x1,x2) )
debut = x2 + 2
return res

def numero_deux (impair, pair) :
moypair   = sum (pair)   / len (pair)         # vaut 25
moyimpair = sum (impair) / len (impair)       # vaut 41
im        = numerotation (impair, 1, moyimpair)
pa        = numerotation (pair,   2, moypair)
return im,pa

impair = [20,70,35]
pair   = [20,20,40,35,10]
im,pa  = numero_deux (impair, pair)
print im
print pa

```

File: ecrit_2009_rattrapage.tex, line 83

```
[(1, 1), (3, 5), (7, 7)]
[(2, 2), (4, 4), (6, 8), (10, 12), (14, 14)]

```

File: ecrit_2009_rattrapage.tex, line 108

```
a = [ None, [0] ]
b = [ None, [0] ]
c = [ None, [0] ]

a [0] = b
b [0] = c
c [0] = a

x = a
for i in range (0, 9) :
x [1][0] += 1
x = x [0]

print "a [1][0] =", a [1][0]
print "b [1][0] =", b [1][0]
print "c [1][0] =", c [1][0]

```

File: ecrit_2009_rattrapage.tex, line 131

```
a = [ None, [0] ]
b = [ None, [0] ]
c = [ None, [0] ]

a [0] = b
b [0] = c
c [0] = a

import copy             # ligne ajoutée
a = copy.copy (a)       # ligne ajoutée

x = a
for i in range (0, 9) :
x [1][0] += 1
x = x [0]

print "a [1][0] =", a [1][0]
print "b [1][0] =", b [1][0]
print "c [1][0] =", c [1][0]

```

File: ecrit_2009_rattrapage.tex, line 157

```
a = [ None, [0] ]
b = [ None, [0] ]
c = [ None, [0] ]

a [0] = b
b [0] = c
c [0] = a

import copy
a = copy.deepcopy (a)     # ligne modifiée

x = a
for i in range (0, 9) :
x [1][0] += 1
x = x [0]

print "a [1][0] =", a [1][0]
print "b [1][0] =", b [1][0]
print "c [1][0] =", c [1][0]

```