Académique Documents
Professionnel Documents
Culture Documents
Exercice 1 : Exercice 5 :
if n==0: if len(s)==0:
print('') return 0
else: else:
décroissant(n-1) Exercice 6 :
Exercice 2 : def rev(L):
if n==0: return L
print('') else:
croissant(n-1) Exercice 7 :
Exercice 3 : if len(ch)<2:
if a==1: if ch[0]!=ch[-1]:
1
Version itérative :
Exercice 9 :
def reverse(L):
def reverse(L):
seq=[]
if len(L)==0:
for i in range(len(L)):
return []
seq.insert(0,L[i])
else:
return seq
return reverse(L[1:])+[L[0]]
Exercice 10 :
def max_iterative(L):
m=L[0] def max_recursive(L):
for i in L:
if len(L)==1:
if i>m:
m=i return L[0]
return m
elif L[0]>L[1]:
while True:
try: L[1]=L[0]
n= int(input("donner la taille :"))
L=L[1:]
if n==0:
raise ValueError('la taille de la liste doit être non nulle') return max_recursive(L)
break
except ValueError:
print("Essayez de nouveau")
L=[]
for i in range(n):
L.append(float(input('donner un élément')))
print("le maximum est",max_iterative(L) )