Exercice 62
Etant donné une liste d'entiers L, écrire un algorithme en Python qui permet de multiplier les éléments de L d'index pair par 2 et ceux d'index impair par 3.
Exemple si L = [3 , 2 , 7 , 11 , 5 , 3], l'algorithme renvoie la liste [6 , 6 , 14 , 33 , 10 , 9]
Solution
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#coding: utf-8 def mult(L): # initialiser la liste recherchée listMult = [] for n in L: if n%2 == 0: listMult.append(2*n) else: listMult.append(3*n) return listMult # Exemple L = [3 , 2 , 7 , 11 , 5 , 3] print(mult(L)) # affiche [9, 4, 21, 33, 15, 9] |
Younes Derfoufi
![[App intégrée] 2025 Upgraded Vidéoprojecteur 1920 * 1080P FHD 4K Mini Projecteur Portable Dual Contrôle avec Souris Android TV WiFi 6 BT5.2 180° Rotation Compatible avec HDMI/TV Stick/USB](https://www.tresfacile.net/wp-content/uploads/2025/12/Videoprojecteur-1920-1080P-FHD-4K-Mini-Projecteur-Portable-Dual-Control-250x236.png)


1 thought on “Solution Exercice 62: algorithme qui multiplie les éléments d'une suite”