Spaces:
Running
Running
Upload code.txt
Browse files
code.txt
CHANGED
|
@@ -15,7 +15,7 @@ Exemple :
|
|
| 15 |
```
|
| 16 |
;;;
|
| 17 |
c = ""
|
| 18 |
-
if moyenne([10, 15, 20]) == 15:
|
| 19 |
c += "1"
|
| 20 |
else :
|
| 21 |
c += "0"
|
|
@@ -23,6 +23,14 @@ if moyenne([8, 11, 17, 10]) == 11.5:
|
|
| 23 |
c += "1"
|
| 24 |
else :
|
| 25 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
;;;
|
| 27 |
est voyelle
|
| 28 |
;;;
|
|
@@ -54,6 +62,14 @@ if est_voyelle('y') == True:
|
|
| 54 |
c += "1"
|
| 55 |
else:
|
| 56 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
;;;
|
| 58 |
maximum tableau
|
| 59 |
;;;
|
|
@@ -88,6 +104,14 @@ if maximum_tableau([-27, -24, -3, 15]) == 15:
|
|
| 88 |
c += "1"
|
| 89 |
else :
|
| 90 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
;;;
|
| 92 |
mot de passe valide
|
| 93 |
;;;
|
|
@@ -119,12 +143,16 @@ if mdp_valide('MonSuperMDP12') == True:
|
|
| 119 |
c += "1"
|
| 120 |
else:
|
| 121 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
;;;
|
| 123 |
recherche
|
| 124 |
;;;
|
| 125 |
2
|
| 126 |
;;;
|
| 127 |
-
tableau (liste Python), boucle for, parcours d'un tableau, utilisation de l'indice
|
| 128 |
;;;
|
| 129 |
Programmer la fonction `recherche`, prenant en paramètres un tableau non vide tab (type list) d’entiers et un entier `n`, et qui renvoie l’indice de la première occurrence de l’élément cherché.
|
| 130 |
Si l’élément n’est pas présent, la fonction renvoie `None`.
|
|
@@ -150,6 +178,14 @@ if recherche([2,3,5,2,4],2) == 0:
|
|
| 150 |
c += "1"
|
| 151 |
else :
|
| 152 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
;;;
|
| 154 |
est bissextile
|
| 155 |
;;;
|
|
@@ -182,6 +218,14 @@ if est_bissextile(2000) == True:
|
|
| 182 |
c += "1"
|
| 183 |
else:
|
| 184 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
;;;
|
| 186 |
dernier chiffre
|
| 187 |
;;;
|
|
@@ -213,6 +257,14 @@ if dernier_chiffre(1980) == 0:
|
|
| 213 |
c += "1"
|
| 214 |
else:
|
| 215 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
;;;
|
| 217 |
max et indice
|
| 218 |
;;;
|
|
@@ -251,6 +303,14 @@ if max_et_indice([1, 1, 1, 1]) == (1, 0):
|
|
| 251 |
c += "1"
|
| 252 |
else :
|
| 253 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
;;;
|
| 255 |
tarification
|
| 256 |
;;;
|
|
@@ -285,6 +345,14 @@ if tarification(25) == 'Plein tarif':
|
|
| 285 |
c += "1"
|
| 286 |
else:
|
| 287 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
;;;
|
| 289 |
prix TTC
|
| 290 |
;;;
|
|
@@ -310,6 +378,10 @@ if prix_ttc(50, 5.5) == 52.75:
|
|
| 310 |
c += "1"
|
| 311 |
else:
|
| 312 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
;;;
|
| 314 |
verifie
|
| 315 |
;;;
|
|
@@ -390,6 +462,14 @@ if mention_bac(8.5) == 'Recalé':
|
|
| 390 |
c += "1"
|
| 391 |
else:
|
| 392 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
;;;
|
| 394 |
premier et dernier
|
| 395 |
;;;
|
|
@@ -421,6 +501,14 @@ if premier_dernier([42]) == (42, 42):
|
|
| 421 |
c += "1"
|
| 422 |
else :
|
| 423 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
;;;
|
| 425 |
delta encoding
|
| 426 |
;;;
|
|
@@ -448,6 +536,14 @@ if delta([42]) == [42]:
|
|
| 448 |
c += "1"
|
| 449 |
else :
|
| 450 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
;;;
|
| 452 |
moyenne pondérée
|
| 453 |
;;;
|
|
@@ -475,6 +571,10 @@ if moyenne([(3, 0), (5, 0)]) == None:
|
|
| 475 |
c += "1"
|
| 476 |
else :
|
| 477 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
;;;
|
| 479 |
tri sélection
|
| 480 |
;;;
|
|
@@ -500,6 +600,14 @@ if tri_selection([6]) == [6]:
|
|
| 500 |
c += "1"
|
| 501 |
else :
|
| 502 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
;;;
|
| 504 |
salutation
|
| 505 |
;;;
|
|
@@ -525,6 +633,14 @@ if salutation("Bob", 20) == 'Bonsoir Bob':
|
|
| 525 |
c += "1"
|
| 526 |
else:
|
| 527 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
;;;
|
| 529 |
min et max
|
| 530 |
;;;
|
|
@@ -569,6 +685,14 @@ if min_et_max([-1, -1, -1, -1, -1]) == {'min': -1, 'max': -1}:
|
|
| 569 |
c += "1"
|
| 570 |
else :
|
| 571 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
;;;
|
| 573 |
nombre de répétitions
|
| 574 |
;;;
|
|
@@ -592,7 +716,7 @@ if nb_repetitions(5, [2, 5, 3, 5, 6, 9, 5]) == 3:
|
|
| 592 |
c += "1"
|
| 593 |
else :
|
| 594 |
c += "0"
|
| 595 |
-
if nb_repetitions('A', ['B', 'A', 'B', 'A', 'R']) == 2
|
| 596 |
c += "1"
|
| 597 |
else :
|
| 598 |
c += "0"
|
|
@@ -600,6 +724,14 @@ if nb_repetitions(12, [1, 3, 7, 21, 36, 44]) == 0:
|
|
| 600 |
c += "1"
|
| 601 |
else :
|
| 602 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
;;;
|
| 604 |
volume cube
|
| 605 |
;;;
|
|
@@ -625,12 +757,20 @@ if volume_cube(10) == 1000:
|
|
| 625 |
c += "1"
|
| 626 |
else:
|
| 627 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
;;;
|
| 629 |
recherche motif
|
| 630 |
;;;
|
| 631 |
3
|
| 632 |
;;;
|
| 633 |
-
chaine de caractère, parcours d'une chaine, recherche d'un motif
|
| 634 |
;;;
|
| 635 |
Écrire une fonction `recherche_motif` qui prend en paramètres une chaîne de caractères motif non vide et une chaîne de caractères texte et qui renvoie la liste des positions de motif dans texte. Si motif n’apparaît pas, la fonction renvoie une liste vide.
|
| 636 |
Exemples:
|
|
@@ -662,6 +802,14 @@ if recherche_motif("ab", "abracadabraab") == [0, 7, 11]:
|
|
| 662 |
c+="1"
|
| 663 |
else :
|
| 664 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
;;;
|
| 666 |
recherche indice classement
|
| 667 |
;;;
|
|
@@ -702,6 +850,10 @@ if recherche_indices_classement(3, []) == ([], [], []):
|
|
| 702 |
c+="1"
|
| 703 |
else :
|
| 704 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 705 |
;;;
|
| 706 |
signe
|
| 707 |
;;;
|
|
@@ -736,6 +888,10 @@ if signe(0) == 'nul':
|
|
| 736 |
c += "1"
|
| 737 |
else:
|
| 738 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
;;;
|
| 740 |
(T) parcours largeur arbre
|
| 741 |
;;;
|
|
@@ -794,6 +950,14 @@ if recherche_min([-1, -2, -3, -3]) == 2:
|
|
| 794 |
c+="1"
|
| 795 |
else :
|
| 796 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
;;;
|
| 798 |
ajoute dictionnaire
|
| 799 |
;;;
|
|
@@ -915,10 +1079,15 @@ if moyenne(5, 10, 15) == 10:
|
|
| 915 |
c+="1"
|
| 916 |
else :
|
| 917 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
;;;
|
| 919 |
(T) recheche arbre binaire de recherche
|
| 920 |
;;;
|
| 921 |
-
|
| 922 |
;;;
|
| 923 |
programmation orientée objet, recherche dans arbre binaire de recherche
|
| 924 |
;;;
|
|
@@ -926,7 +1095,7 @@ programmation orientée objet, recherche dans arbre binaire de recherche
|
|
| 926 |
La classe Arbre possède 3 méthodes :
|
| 927 |
- `get_gauche()` renvoie l'arbre gauche
|
| 928 |
- g`et_droit()` renvoie l'arbre droit
|
| 929 |
-
- `get_valeur()` renvoie la valeur du noeud
|
| 930 |
;;;
|
| 931 |
class ArbreBinaire:
|
| 932 |
def __init__(self, valeur):
|
|
@@ -1071,6 +1240,10 @@ if fusion([1, 2, 3], []) == [1, 2, 3]:
|
|
| 1071 |
c+="1"
|
| 1072 |
else :
|
| 1073 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1074 |
;;;
|
| 1075 |
multiplication
|
| 1076 |
;;;
|
|
@@ -1159,7 +1332,7 @@ Par exemple : avec la phrase 'Hello world !' le dictionnaire est le suivant :
|
|
| 1159 |
{'H': 1,'e': 1,'l': 3,'o': 2,' ': 2,'w': 1,'r': 1,'d': 1,'!': 1}
|
| 1160 |
```
|
| 1161 |
L’ordre des clefs n’a pas d’importance.
|
| 1162 |
-
Écrire une fonction `nbr_occurrences` prenant comme paramètre une chaîne de caractères `chaine` et renvoyant le dictionnaire des nombres d’occurrences des caractères de cette chaîne.
|
| 1163 |
;;;
|
| 1164 |
c=""
|
| 1165 |
if nbr_occurrences('Hello world !') == {'H': 1,'e': 1,'l': 3,'o': 2,' ': 2,'w': 1,'r': 1,'d': 1,'!': 1}:
|
|
@@ -1270,6 +1443,14 @@ if indices_maxi([7]) == (7, [0]):
|
|
| 1270 |
c+="1"
|
| 1271 |
else :
|
| 1272 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1273 |
;;;
|
| 1274 |
addition
|
| 1275 |
;;;
|
|
@@ -1423,6 +1604,11 @@ if somme([]) == 0:
|
|
| 1423 |
c+="1"
|
| 1424 |
else :
|
| 1425 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1426 |
;;;
|
| 1427 |
énumère
|
| 1428 |
;;;
|
|
@@ -1483,7 +1669,7 @@ if max_dico({ 'Bob': 102, 'Ada': 201, 'Alice': 103, 'Tim': 50 }) == ('Ada', 201)
|
|
| 1483 |
c+="1"
|
| 1484 |
else :
|
| 1485 |
c+="0"
|
| 1486 |
-
if max_dico({ 'Alan': 222, 'Ada': 201, 'Eve': 222, 'Tim': 50 })
|
| 1487 |
c+="1"
|
| 1488 |
else :
|
| 1489 |
c+="0"
|
|
@@ -1492,7 +1678,7 @@ correspond
|
|
| 1492 |
;;;
|
| 1493 |
3
|
| 1494 |
;;;
|
| 1495 |
-
chaîne de caractères, parcours d'une chaine, if, condition avec and et or
|
| 1496 |
;;;
|
| 1497 |
On considère des chaînes de caractères contenant uniquement des majuscules et des caractères * appelées mots à trous.
|
| 1498 |
Par exemple INFO*MA*IQUE, ***I***E** et *S* sont des mots à trous.
|
|
@@ -1648,7 +1834,7 @@ L’algorithme demandé est une recherche dichotomique récursive.
|
|
| 1648 |
Exemples :
|
| 1649 |
>>> chercher([1, 5, 6, 9, 12], 7)
|
| 1650 |
>>> chercher([1, 5, 6, 9, 12], 9)
|
| 1651 |
-
|
| 1652 |
>>> chercher([1, 5, 6, 9, 12], 6)
|
| 1653 |
2
|
| 1654 |
```
|
|
@@ -1666,6 +1852,14 @@ if chercher([1, 5, 6, 9, 12], 6) == 2:
|
|
| 1666 |
c+="1"
|
| 1667 |
else :
|
| 1668 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1669 |
;;;
|
| 1670 |
moyenne dico
|
| 1671 |
;;;
|
|
@@ -1726,7 +1920,7 @@ arbre, programmation orientée objet, parcours d'un arbre
|
|
| 1726 |
La classe `Arbre` possède 3 méthodes :
|
| 1727 |
- `get_gauche()` renvoie l'arbre gauche
|
| 1728 |
- `get_droit()` renvoie l'arbre droit
|
| 1729 |
-
- `get_valeur()` renvoie la valeur du noeud
|
| 1730 |
;;;
|
| 1731 |
class ArbreBinaire:
|
| 1732 |
def __init__(self, valeur):
|
|
@@ -1891,10 +2085,18 @@ if somme_max([-3,-2,-1,-4]) == -1 :
|
|
| 1891 |
c+="1"
|
| 1892 |
else :
|
| 1893 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1894 |
;;;
|
| 1895 |
(T) taille d'un arbre binaire
|
| 1896 |
;;;
|
| 1897 |
-
|
| 1898 |
;;;
|
| 1899 |
arbre binaire, programmation orientée objet, taille d'un arbre
|
| 1900 |
;;;
|
|
@@ -1902,7 +2104,7 @@ arbre binaire, programmation orientée objet, taille d'un arbre
|
|
| 1902 |
La classe `Arbre` possède 3 méthodes :
|
| 1903 |
- g`et_gauche()` renvoie l'arbre gauche
|
| 1904 |
- `get_droit()` renvoie l'arbre droit
|
| 1905 |
-
- `get_valeur()` renvoie la valeur du noeud
|
| 1906 |
;;;
|
| 1907 |
class ArbreBinaire:
|
| 1908 |
def __init__(self, valeur):
|
|
@@ -2021,7 +2223,7 @@ arbre, programmation orientée objet, parcours d'un arbre
|
|
| 2021 |
La classe `Arbre` possède 3 méthodes :
|
| 2022 |
- `get_gauche()` renvoie l'arbre gauche
|
| 2023 |
- `get_droit()` renvoie l'arbre droit
|
| 2024 |
-
- `get_valeur()` renvoie la valeur du noeud
|
| 2025 |
;;;
|
| 2026 |
class ArbreBinaire:
|
| 2027 |
def __init__(self, valeur):
|
|
@@ -2118,6 +2320,14 @@ if not dichotomie([15, 16, 18, 19, 23, 24, 28, 29, 31, 33],27):
|
|
| 2118 |
c+="1"
|
| 2119 |
else :
|
| 2120 |
c+="0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2121 |
;;;
|
| 2122 |
(T) parcours infixe d'un arbre binaire
|
| 2123 |
;;;
|
|
@@ -2129,7 +2339,7 @@ arbre binaire, programmation orientée objet, parcours arbre binaire
|
|
| 2129 |
La classe `Arbre` possède 3 méthodes :
|
| 2130 |
- `get_gauche()` renvoie l'arbre gauche
|
| 2131 |
- `get_droit()` renvoie l'arbre droit
|
| 2132 |
-
- `get_valeur()` renvoie la valeur du noeud
|
| 2133 |
;;;
|
| 2134 |
class ArbreBinaire:
|
| 2135 |
def __init__(self, valeur):
|
|
@@ -2236,7 +2446,7 @@ else :
|
|
| 2236 |
;;;
|
| 2237 |
(T) hauteur d'un arbre binaire
|
| 2238 |
;;;
|
| 2239 |
-
|
| 2240 |
;;;
|
| 2241 |
arbre binaire, programmation orientée objet, hauteur d'un arbre
|
| 2242 |
;;;
|
|
@@ -2244,7 +2454,7 @@ arbre binaire, programmation orientée objet, hauteur d'un arbre
|
|
| 2244 |
La classe `Arbre` possède 3 méthodes :
|
| 2245 |
- `get_gauche()` renvoie l'arbre gauche
|
| 2246 |
- `get_droit()` renvoie l'arbre droit
|
| 2247 |
-
- `get_valeur()` renvoie la valeur du noeud
|
| 2248 |
;;;
|
| 2249 |
class ArbreBinaire:
|
| 2250 |
def __init__(self, valeur):
|
|
@@ -2613,7 +2823,7 @@ if est_anagramme("chien", "niche"):
|
|
| 2613 |
c += "1"
|
| 2614 |
else:
|
| 2615 |
c += "0"
|
| 2616 |
-
if est_anagramme("marie
|
| 2617 |
c += "1"
|
| 2618 |
else:
|
| 2619 |
c += "0"
|
|
@@ -2801,6 +3011,10 @@ if plus_petit_moyenne([1, 1, 1, 1, 1]) == []:
|
|
| 2801 |
c += "1"
|
| 2802 |
else:
|
| 2803 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2804 |
;;;
|
| 2805 |
somme des chiffres
|
| 2806 |
;;;
|
|
@@ -2868,7 +3082,7 @@ else:
|
|
| 2868 |
;;;
|
| 2869 |
(T) somme des éléments d'un tableau
|
| 2870 |
;;;
|
| 2871 |
-
|
| 2872 |
;;;
|
| 2873 |
tableau (liste Python), récursivité, somme
|
| 2874 |
;;;
|
|
@@ -2896,6 +3110,11 @@ if somme_recursive([10]) == 10:
|
|
| 2896 |
c += "1"
|
| 2897 |
else:
|
| 2898 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2899 |
;;;
|
| 2900 |
calcul surface rectangle
|
| 2901 |
;;;
|
|
@@ -3068,7 +3287,7 @@ else:
|
|
| 3068 |
;;;
|
| 3069 |
somme des nombres pairs d'un tableau
|
| 3070 |
;;;
|
| 3071 |
-
2
|
| 3072 |
;;;
|
| 3073 |
tableau (liste Python), boucle for, condition (if), modulo, somme
|
| 3074 |
;;;
|
|
@@ -3084,27 +3303,31 @@ Exemples :
|
|
| 3084 |
20
|
| 3085 |
>>> somme_pairs([])
|
| 3086 |
0
|
| 3087 |
-
```
|
| 3088 |
;;;
|
| 3089 |
c = ""
|
| 3090 |
-
if somme_pairs([1, 2, 3, 4, 5, 6]) == 12:
|
| 3091 |
-
|
| 3092 |
-
else:
|
| 3093 |
-
|
| 3094 |
-
if somme_pairs([1, 3, 5, 7]) == 0:
|
| 3095 |
-
|
| 3096 |
-
else:
|
| 3097 |
-
|
| 3098 |
-
if somme_pairs([2, 4, 6, 8]) == 20:
|
| 3099 |
-
|
| 3100 |
-
else:
|
| 3101 |
-
|
| 3102 |
-
if somme_pairs([]) == 0:
|
| 3103 |
-
|
| 3104 |
-
else:
|
| 3105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3106 |
;;;
|
| 3107 |
-
(T) est un palindrome bis
|
| 3108 |
;;;
|
| 3109 |
3
|
| 3110 |
;;;
|
|
@@ -3154,7 +3377,7 @@ Exemples :
|
|
| 3154 |
>>> nombre_voyelles("Bonjour")
|
| 3155 |
3
|
| 3156 |
>>> nombre_voyelles("Python")
|
| 3157 |
-
|
| 3158 |
>>> nombre_voyelles("AEIOUY")
|
| 3159 |
6
|
| 3160 |
>>> nombre_voyelles("")
|
|
@@ -3178,6 +3401,10 @@ if nombre_voyelles("") == 0:
|
|
| 3178 |
c += "1"
|
| 3179 |
else:
|
| 3180 |
c += "0"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3181 |
;;;
|
| 3182 |
est un triangle rectangle ?
|
| 3183 |
;;;
|
|
@@ -3210,3 +3437,488 @@ if not est_rectangle(6, 8, 11):
|
|
| 3210 |
else:
|
| 3211 |
c += "0"
|
| 3212 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
```
|
| 16 |
;;;
|
| 17 |
c = ""
|
| 18 |
+
if moyenne([10, 15, 20]) == 15.0:
|
| 19 |
c += "1"
|
| 20 |
else :
|
| 21 |
c += "0"
|
|
|
|
| 23 |
c += "1"
|
| 24 |
else :
|
| 25 |
c += "0"
|
| 26 |
+
if moyenne([5, 15]) == 10.0:
|
| 27 |
+
c += '1'
|
| 28 |
+
else:
|
| 29 |
+
c += '0'
|
| 30 |
+
if moyenne([10, 20, 30, 40]) == 25.0:
|
| 31 |
+
c += "1"
|
| 32 |
+
else :
|
| 33 |
+
c += "0"
|
| 34 |
;;;
|
| 35 |
est voyelle
|
| 36 |
;;;
|
|
|
|
| 62 |
c += "1"
|
| 63 |
else:
|
| 64 |
c += "0"
|
| 65 |
+
if est_voyelle('u') == True:
|
| 66 |
+
c += '1'
|
| 67 |
+
else:
|
| 68 |
+
c += '0'
|
| 69 |
+
if est_voyelle('o') == True:
|
| 70 |
+
c += "1"
|
| 71 |
+
else :
|
| 72 |
+
c += "0"
|
| 73 |
;;;
|
| 74 |
maximum tableau
|
| 75 |
;;;
|
|
|
|
| 104 |
c += "1"
|
| 105 |
else :
|
| 106 |
c += "0"
|
| 107 |
+
if maximum_tableau([10, 20, 5, 25, 15]) == 25:
|
| 108 |
+
c += '1'
|
| 109 |
+
else:
|
| 110 |
+
c += '0'
|
| 111 |
+
if maximum_tableau([10, 50, 20, 30]) == 50:
|
| 112 |
+
c += "1"
|
| 113 |
+
else :
|
| 114 |
+
c += "0"
|
| 115 |
;;;
|
| 116 |
mot de passe valide
|
| 117 |
;;;
|
|
|
|
| 143 |
c += "1"
|
| 144 |
else:
|
| 145 |
c += "0"
|
| 146 |
+
if mdp_valide('abc') == False:
|
| 147 |
+
c += '1'
|
| 148 |
+
else:
|
| 149 |
+
c += '0'
|
| 150 |
;;;
|
| 151 |
recherche
|
| 152 |
;;;
|
| 153 |
2
|
| 154 |
;;;
|
| 155 |
+
tableau (liste Python), boucle for, parcours d'un tableau, utilisation de l'indice
|
| 156 |
;;;
|
| 157 |
Programmer la fonction `recherche`, prenant en paramètres un tableau non vide tab (type list) d’entiers et un entier `n`, et qui renvoie l’indice de la première occurrence de l’élément cherché.
|
| 158 |
Si l’élément n’est pas présent, la fonction renvoie `None`.
|
|
|
|
| 178 |
c += "1"
|
| 179 |
else :
|
| 180 |
c += "0"
|
| 181 |
+
if recherche([10, 20, 30], 40) == None:
|
| 182 |
+
c += '1'
|
| 183 |
+
else:
|
| 184 |
+
c += '0'
|
| 185 |
+
if recherche([1, 2, 3, 4, 5], 3) == 2:
|
| 186 |
+
c += "1"
|
| 187 |
+
else :
|
| 188 |
+
c += "0"
|
| 189 |
;;;
|
| 190 |
est bissextile
|
| 191 |
;;;
|
|
|
|
| 218 |
c += "1"
|
| 219 |
else:
|
| 220 |
c += "0"
|
| 221 |
+
if est_bissextile(2024) == True:
|
| 222 |
+
c += '1'
|
| 223 |
+
else:
|
| 224 |
+
c += '0'
|
| 225 |
+
if est_bissextile(1900) == False:
|
| 226 |
+
c += "1"
|
| 227 |
+
else :
|
| 228 |
+
c += "0"
|
| 229 |
;;;
|
| 230 |
dernier chiffre
|
| 231 |
;;;
|
|
|
|
| 257 |
c += "1"
|
| 258 |
else:
|
| 259 |
c += "0"
|
| 260 |
+
if dernier_chiffre(2023) == 3:
|
| 261 |
+
c += '1'
|
| 262 |
+
else:
|
| 263 |
+
c += '0'
|
| 264 |
+
if dernier_chiffre(99) == 9:
|
| 265 |
+
c += "1"
|
| 266 |
+
else :
|
| 267 |
+
c += "0"
|
| 268 |
;;;
|
| 269 |
max et indice
|
| 270 |
;;;
|
|
|
|
| 303 |
c += "1"
|
| 304 |
else :
|
| 305 |
c += "0"
|
| 306 |
+
if max_et_indice([1, 9, 2, 9]) == (9, 1):
|
| 307 |
+
c += '1'
|
| 308 |
+
else:
|
| 309 |
+
c += '0'
|
| 310 |
+
if max_et_indice([5, 8, 2, 8]) == (8, 1):
|
| 311 |
+
c += "1"
|
| 312 |
+
else :
|
| 313 |
+
c += "0"
|
| 314 |
;;;
|
| 315 |
tarification
|
| 316 |
;;;
|
|
|
|
| 345 |
c += "1"
|
| 346 |
else:
|
| 347 |
c += "0"
|
| 348 |
+
if tarification(11) == 'Demi-tarif':
|
| 349 |
+
c += '1'
|
| 350 |
+
else:
|
| 351 |
+
c += '0'
|
| 352 |
+
if tarification(5) == 'Demi-tarif':
|
| 353 |
+
c += "1"
|
| 354 |
+
else :
|
| 355 |
+
c += "0"
|
| 356 |
;;;
|
| 357 |
prix TTC
|
| 358 |
;;;
|
|
|
|
| 378 |
c += "1"
|
| 379 |
else:
|
| 380 |
c += "0"
|
| 381 |
+
if prix_ttc(200, 10) == 220.0:
|
| 382 |
+
c += '1'
|
| 383 |
+
else:
|
| 384 |
+
c += '0'
|
| 385 |
;;;
|
| 386 |
verifie
|
| 387 |
;;;
|
|
|
|
| 462 |
c += "1"
|
| 463 |
else:
|
| 464 |
c += "0"
|
| 465 |
+
if mention_bac(14.5) == 'Bien':
|
| 466 |
+
c += '1'
|
| 467 |
+
else:
|
| 468 |
+
c += '0'
|
| 469 |
+
if mention_bac(11) == 'Passable':
|
| 470 |
+
c += "1"
|
| 471 |
+
else :
|
| 472 |
+
c += "0"
|
| 473 |
;;;
|
| 474 |
premier et dernier
|
| 475 |
;;;
|
|
|
|
| 501 |
c += "1"
|
| 502 |
else :
|
| 503 |
c += "0"
|
| 504 |
+
if premier_dernier([1, 2, 3]) == (1, 3):
|
| 505 |
+
c += '1'
|
| 506 |
+
else:
|
| 507 |
+
c += '0'
|
| 508 |
+
if premier_dernier(['A', 'B', 'C']) == ('A', 'C'):
|
| 509 |
+
c += "1"
|
| 510 |
+
else :
|
| 511 |
+
c += "0"
|
| 512 |
;;;
|
| 513 |
delta encoding
|
| 514 |
;;;
|
|
|
|
| 536 |
c += "1"
|
| 537 |
else :
|
| 538 |
c += "0"
|
| 539 |
+
if delta([10, 15, 12]) == [10, 5, -3]:
|
| 540 |
+
c += '1'
|
| 541 |
+
else:
|
| 542 |
+
c += '0'
|
| 543 |
+
if delta([100, 100, 100]) == [100, 0, 0]:
|
| 544 |
+
c += "1"
|
| 545 |
+
else :
|
| 546 |
+
c += "0"
|
| 547 |
;;;
|
| 548 |
moyenne pondérée
|
| 549 |
;;;
|
|
|
|
| 571 |
c += "1"
|
| 572 |
else :
|
| 573 |
c += "0"
|
| 574 |
+
if moyenne([(5,1), (15,1)]) == 10.0:
|
| 575 |
+
c += '1'
|
| 576 |
+
else:
|
| 577 |
+
c += '0'
|
| 578 |
;;;
|
| 579 |
tri sélection
|
| 580 |
;;;
|
|
|
|
| 600 |
c += "1"
|
| 601 |
else :
|
| 602 |
c += "0"
|
| 603 |
+
if tri_selection([3, 1, 2]) == [1, 2, 3]:
|
| 604 |
+
c += '1'
|
| 605 |
+
else:
|
| 606 |
+
c += '0'
|
| 607 |
+
if tri_selection([9, 7, 8]) == [7, 8, 9]:
|
| 608 |
+
c += "1"
|
| 609 |
+
else :
|
| 610 |
+
c += "0"
|
| 611 |
;;;
|
| 612 |
salutation
|
| 613 |
;;;
|
|
|
|
| 633 |
c += "1"
|
| 634 |
else:
|
| 635 |
c += "0"
|
| 636 |
+
if salutation('Antigravity', 9) == 'Bonjour Antigravity':
|
| 637 |
+
c += '1'
|
| 638 |
+
else:
|
| 639 |
+
c += '0'
|
| 640 |
+
if salutation('Bob', 19) == 'Bonsoir Bob':
|
| 641 |
+
c += "1"
|
| 642 |
+
else :
|
| 643 |
+
c += "0"
|
| 644 |
;;;
|
| 645 |
min et max
|
| 646 |
;;;
|
|
|
|
| 685 |
c += "1"
|
| 686 |
else :
|
| 687 |
c += "0"
|
| 688 |
+
if min_et_max([5, 10, 1]) == {'min': 1, 'max': 10}:
|
| 689 |
+
c += '1'
|
| 690 |
+
else:
|
| 691 |
+
c += '0'
|
| 692 |
+
if min_et_max([10, 0, -10]) == {'min': -10, 'max': 10}:
|
| 693 |
+
c += "1"
|
| 694 |
+
else :
|
| 695 |
+
c += "0"
|
| 696 |
;;;
|
| 697 |
nombre de répétitions
|
| 698 |
;;;
|
|
|
|
| 716 |
c += "1"
|
| 717 |
else :
|
| 718 |
c += "0"
|
| 719 |
+
if nb_repetitions('A', ['B', 'A', 'B', 'A', 'R']) == 2:
|
| 720 |
c += "1"
|
| 721 |
else :
|
| 722 |
c += "0"
|
|
|
|
| 724 |
c += "1"
|
| 725 |
else :
|
| 726 |
c += "0"
|
| 727 |
+
if nb_repetitions(1, [1, 2, 1, 3, 1]) == 3:
|
| 728 |
+
c += '1'
|
| 729 |
+
else:
|
| 730 |
+
c += '0'
|
| 731 |
+
if nb_repetitions('X', ['X', 'Y', 'X', 'Z']) == 2:
|
| 732 |
+
c += "1"
|
| 733 |
+
else :
|
| 734 |
+
c += "0"
|
| 735 |
;;;
|
| 736 |
volume cube
|
| 737 |
;;;
|
|
|
|
| 757 |
c += "1"
|
| 758 |
else:
|
| 759 |
c += "0"
|
| 760 |
+
if volume_cube(2) == 8:
|
| 761 |
+
c += '1'
|
| 762 |
+
else:
|
| 763 |
+
c += '0'
|
| 764 |
+
if volume_cube(1) == 1:
|
| 765 |
+
c += "1"
|
| 766 |
+
else :
|
| 767 |
+
c += "0"
|
| 768 |
;;;
|
| 769 |
recherche motif
|
| 770 |
;;;
|
| 771 |
3
|
| 772 |
;;;
|
| 773 |
+
chaine de caractère, parcours d'une chaine, recherche d'un motif
|
| 774 |
;;;
|
| 775 |
Écrire une fonction `recherche_motif` qui prend en paramètres une chaîne de caractères motif non vide et une chaîne de caractères texte et qui renvoie la liste des positions de motif dans texte. Si motif n’apparaît pas, la fonction renvoie une liste vide.
|
| 776 |
Exemples:
|
|
|
|
| 802 |
c+="1"
|
| 803 |
else :
|
| 804 |
c+="0"
|
| 805 |
+
if recherche_motif('aa', 'aaa') == [0, 1]:
|
| 806 |
+
c += '1'
|
| 807 |
+
else:
|
| 808 |
+
c += '0'
|
| 809 |
+
if recherche_motif('ab', 'abracadabra') == [0, 7]:
|
| 810 |
+
c += "1"
|
| 811 |
+
else :
|
| 812 |
+
c += "0"
|
| 813 |
;;;
|
| 814 |
recherche indice classement
|
| 815 |
;;;
|
|
|
|
| 850 |
c+="1"
|
| 851 |
else :
|
| 852 |
c+="0"
|
| 853 |
+
if recherche_indices_classement(10, [5, 10, 15]) == ([0], [1], [2]):
|
| 854 |
+
c += '1'
|
| 855 |
+
else:
|
| 856 |
+
c += '0'
|
| 857 |
;;;
|
| 858 |
signe
|
| 859 |
;;;
|
|
|
|
| 888 |
c += "1"
|
| 889 |
else:
|
| 890 |
c += "0"
|
| 891 |
+
if signe(-10) == 'strictement négatif':
|
| 892 |
+
c += '1'
|
| 893 |
+
else:
|
| 894 |
+
c += '0'
|
| 895 |
;;;
|
| 896 |
(T) parcours largeur arbre
|
| 897 |
;;;
|
|
|
|
| 950 |
c+="1"
|
| 951 |
else :
|
| 952 |
c+="0"
|
| 953 |
+
if recherche_min([1, 2, 3]) == 0:
|
| 954 |
+
c += '1'
|
| 955 |
+
else:
|
| 956 |
+
c += '0'
|
| 957 |
+
if recherche_min([10, 20, 30]) == 0:
|
| 958 |
+
c += "1"
|
| 959 |
+
else :
|
| 960 |
+
c += "0"
|
| 961 |
;;;
|
| 962 |
ajoute dictionnaire
|
| 963 |
;;;
|
|
|
|
| 1079 |
c+="1"
|
| 1080 |
else :
|
| 1081 |
c+="0"
|
| 1082 |
+
if moyenne(5, 5, 5) == 5:
|
| 1083 |
+
c += '1'
|
| 1084 |
+
else:
|
| 1085 |
+
c += '0'
|
| 1086 |
+
|
| 1087 |
;;;
|
| 1088 |
(T) recheche arbre binaire de recherche
|
| 1089 |
;;;
|
| 1090 |
+
3
|
| 1091 |
;;;
|
| 1092 |
programmation orientée objet, recherche dans arbre binaire de recherche
|
| 1093 |
;;;
|
|
|
|
| 1095 |
La classe Arbre possède 3 méthodes :
|
| 1096 |
- `get_gauche()` renvoie l'arbre gauche
|
| 1097 |
- g`et_droit()` renvoie l'arbre droit
|
| 1098 |
+
- `get_valeur()` renvoie la valeur du noeud
|
| 1099 |
;;;
|
| 1100 |
class ArbreBinaire:
|
| 1101 |
def __init__(self, valeur):
|
|
|
|
| 1240 |
c+="1"
|
| 1241 |
else :
|
| 1242 |
c+="0"
|
| 1243 |
+
if fusion([1], [2]) == [1, 2]:
|
| 1244 |
+
c+="1"
|
| 1245 |
+
else :
|
| 1246 |
+
c+="0"
|
| 1247 |
;;;
|
| 1248 |
multiplication
|
| 1249 |
;;;
|
|
|
|
| 1332 |
{'H': 1,'e': 1,'l': 3,'o': 2,' ': 2,'w': 1,'r': 1,'d': 1,'!': 1}
|
| 1333 |
```
|
| 1334 |
L’ordre des clefs n’a pas d’importance.
|
| 1335 |
+
Écrire une fonction `nbr_occurrences` prenant comme paramètre une chaîne de caractères `chaine` et renvoyant le dictionnaire des nombres d’occurrences des caractères de cette chaîne.
|
| 1336 |
;;;
|
| 1337 |
c=""
|
| 1338 |
if nbr_occurrences('Hello world !') == {'H': 1,'e': 1,'l': 3,'o': 2,' ': 2,'w': 1,'r': 1,'d': 1,'!': 1}:
|
|
|
|
| 1443 |
c+="1"
|
| 1444 |
else :
|
| 1445 |
c+="0"
|
| 1446 |
+
if indices_maxi([1, 2,10,10,3]) == (10,[2,3]):
|
| 1447 |
+
c += '1'
|
| 1448 |
+
else:
|
| 1449 |
+
c += '0'
|
| 1450 |
+
if indices_maxi([42, 17, 99]) == (99,[2]):
|
| 1451 |
+
c += "1"
|
| 1452 |
+
else :
|
| 1453 |
+
c += "0"
|
| 1454 |
;;;
|
| 1455 |
addition
|
| 1456 |
;;;
|
|
|
|
| 1604 |
c+="1"
|
| 1605 |
else :
|
| 1606 |
c+="0"
|
| 1607 |
+
|
| 1608 |
+
if somme([1, 2, 3, 4]) == 10:
|
| 1609 |
+
c += "1"
|
| 1610 |
+
else :
|
| 1611 |
+
c += "0"
|
| 1612 |
;;;
|
| 1613 |
énumère
|
| 1614 |
;;;
|
|
|
|
| 1669 |
c+="1"
|
| 1670 |
else :
|
| 1671 |
c+="0"
|
| 1672 |
+
if max_dico({ 'Alan': 222, 'Ada': 201, 'Eve': 222, 'Tim': 50 }) in [('Alan', 222),('Eve', 222)] :
|
| 1673 |
c+="1"
|
| 1674 |
else :
|
| 1675 |
c+="0"
|
|
|
|
| 1678 |
;;;
|
| 1679 |
3
|
| 1680 |
;;;
|
| 1681 |
+
chaîne de caractères, parcours d'une chaine, if, condition avec and et or
|
| 1682 |
;;;
|
| 1683 |
On considère des chaînes de caractères contenant uniquement des majuscules et des caractères * appelées mots à trous.
|
| 1684 |
Par exemple INFO*MA*IQUE, ***I***E** et *S* sont des mots à trous.
|
|
|
|
| 1834 |
Exemples :
|
| 1835 |
>>> chercher([1, 5, 6, 9, 12], 7)
|
| 1836 |
>>> chercher([1, 5, 6, 9, 12], 9)
|
| 1837 |
+
3
|
| 1838 |
>>> chercher([1, 5, 6, 9, 12], 6)
|
| 1839 |
2
|
| 1840 |
```
|
|
|
|
| 1852 |
c+="1"
|
| 1853 |
else :
|
| 1854 |
c+="0"
|
| 1855 |
+
if chercher([1, 2, 3], 2) == 1:
|
| 1856 |
+
c += '1'
|
| 1857 |
+
else:
|
| 1858 |
+
c += '0'
|
| 1859 |
+
if chercher([10, 20, 30], 20) == 1:
|
| 1860 |
+
c += "1"
|
| 1861 |
+
else :
|
| 1862 |
+
c += "0"
|
| 1863 |
;;;
|
| 1864 |
moyenne dico
|
| 1865 |
;;;
|
|
|
|
| 1920 |
La classe `Arbre` possède 3 méthodes :
|
| 1921 |
- `get_gauche()` renvoie l'arbre gauche
|
| 1922 |
- `get_droit()` renvoie l'arbre droit
|
| 1923 |
+
- `get_valeur()` renvoie la valeur du noeud
|
| 1924 |
;;;
|
| 1925 |
class ArbreBinaire:
|
| 1926 |
def __init__(self, valeur):
|
|
|
|
| 2085 |
c+="1"
|
| 2086 |
else :
|
| 2087 |
c+="0"
|
| 2088 |
+
if somme_max([1, 2, 10, 3]) == 16:
|
| 2089 |
+
c+='1'
|
| 2090 |
+
else:
|
| 2091 |
+
c+='0'
|
| 2092 |
+
if somme_max([1, 2, 3, 4]) == 10:
|
| 2093 |
+
c+="1"
|
| 2094 |
+
else :
|
| 2095 |
+
c+="0"
|
| 2096 |
;;;
|
| 2097 |
(T) taille d'un arbre binaire
|
| 2098 |
;;;
|
| 2099 |
+
3
|
| 2100 |
;;;
|
| 2101 |
arbre binaire, programmation orientée objet, taille d'un arbre
|
| 2102 |
;;;
|
|
|
|
| 2104 |
La classe `Arbre` possède 3 méthodes :
|
| 2105 |
- g`et_gauche()` renvoie l'arbre gauche
|
| 2106 |
- `get_droit()` renvoie l'arbre droit
|
| 2107 |
+
- `get_valeur()` renvoie la valeur du noeud
|
| 2108 |
;;;
|
| 2109 |
class ArbreBinaire:
|
| 2110 |
def __init__(self, valeur):
|
|
|
|
| 2223 |
La classe `Arbre` possède 3 méthodes :
|
| 2224 |
- `get_gauche()` renvoie l'arbre gauche
|
| 2225 |
- `get_droit()` renvoie l'arbre droit
|
| 2226 |
+
- `get_valeur()` renvoie la valeur du noeud
|
| 2227 |
;;;
|
| 2228 |
class ArbreBinaire:
|
| 2229 |
def __init__(self, valeur):
|
|
|
|
| 2320 |
c+="1"
|
| 2321 |
else :
|
| 2322 |
c+="0"
|
| 2323 |
+
if dichotomie([1, 2, 3], 2):
|
| 2324 |
+
c += '1'
|
| 2325 |
+
else:
|
| 2326 |
+
c += '0'
|
| 2327 |
+
if not dichotomie([10, 20, 30], 40):
|
| 2328 |
+
c += "1"
|
| 2329 |
+
else :
|
| 2330 |
+
c += "0"
|
| 2331 |
;;;
|
| 2332 |
(T) parcours infixe d'un arbre binaire
|
| 2333 |
;;;
|
|
|
|
| 2339 |
La classe `Arbre` possède 3 méthodes :
|
| 2340 |
- `get_gauche()` renvoie l'arbre gauche
|
| 2341 |
- `get_droit()` renvoie l'arbre droit
|
| 2342 |
+
- `get_valeur()` renvoie la valeur du noeud
|
| 2343 |
;;;
|
| 2344 |
class ArbreBinaire:
|
| 2345 |
def __init__(self, valeur):
|
|
|
|
| 2446 |
;;;
|
| 2447 |
(T) hauteur d'un arbre binaire
|
| 2448 |
;;;
|
| 2449 |
+
3
|
| 2450 |
;;;
|
| 2451 |
arbre binaire, programmation orientée objet, hauteur d'un arbre
|
| 2452 |
;;;
|
|
|
|
| 2454 |
La classe `Arbre` possède 3 méthodes :
|
| 2455 |
- `get_gauche()` renvoie l'arbre gauche
|
| 2456 |
- `get_droit()` renvoie l'arbre droit
|
| 2457 |
+
- `get_valeur()` renvoie la valeur du noeud
|
| 2458 |
;;;
|
| 2459 |
class ArbreBinaire:
|
| 2460 |
def __init__(self, valeur):
|
|
|
|
| 2823 |
c += "1"
|
| 2824 |
else:
|
| 2825 |
c += "0"
|
| 2826 |
+
if est_anagramme("marie", "aimer"):
|
| 2827 |
c += "1"
|
| 2828 |
else:
|
| 2829 |
c += "0"
|
|
|
|
| 3011 |
c += "1"
|
| 3012 |
else:
|
| 3013 |
c += "0"
|
| 3014 |
+
if plus_petit_moyenne([5, 15]) == [5]:
|
| 3015 |
+
c += '1'
|
| 3016 |
+
else:
|
| 3017 |
+
c += '0'
|
| 3018 |
;;;
|
| 3019 |
somme des chiffres
|
| 3020 |
;;;
|
|
|
|
| 3082 |
;;;
|
| 3083 |
(T) somme des éléments d'un tableau
|
| 3084 |
;;;
|
| 3085 |
+
3
|
| 3086 |
;;;
|
| 3087 |
tableau (liste Python), récursivité, somme
|
| 3088 |
;;;
|
|
|
|
| 3110 |
c += "1"
|
| 3111 |
else:
|
| 3112 |
c += "0"
|
| 3113 |
+
|
| 3114 |
+
if somme_recursive([1, 2, 3, 4]) == 10:
|
| 3115 |
+
c += "1"
|
| 3116 |
+
else :
|
| 3117 |
+
c += "0"
|
| 3118 |
;;;
|
| 3119 |
calcul surface rectangle
|
| 3120 |
;;;
|
|
|
|
| 3287 |
;;;
|
| 3288 |
somme des nombres pairs d'un tableau
|
| 3289 |
;;;
|
| 3290 |
+
2
|
| 3291 |
;;;
|
| 3292 |
tableau (liste Python), boucle for, condition (if), modulo, somme
|
| 3293 |
;;;
|
|
|
|
| 3303 |
20
|
| 3304 |
>>> somme_pairs([])
|
| 3305 |
0
|
| 3306 |
+
```
|
| 3307 |
;;;
|
| 3308 |
c = ""
|
| 3309 |
+
if somme_pairs([1, 2, 3, 4, 5, 6]) == 12:
|
| 3310 |
+
c+="1"
|
| 3311 |
+
else:
|
| 3312 |
+
c+="0"
|
| 3313 |
+
if somme_pairs([1, 3, 5, 7]) == 0:
|
| 3314 |
+
c+="1"
|
| 3315 |
+
else:
|
| 3316 |
+
c+="0"
|
| 3317 |
+
if somme_pairs([2, 4, 6, 8]) == 20:
|
| 3318 |
+
c+="1"
|
| 3319 |
+
else:
|
| 3320 |
+
c+="0"
|
| 3321 |
+
if somme_pairs([]) == 0:
|
| 3322 |
+
c+="1"
|
| 3323 |
+
else:
|
| 3324 |
+
c+="0"
|
| 3325 |
+
if somme_pairs([1, 2, 3, 4]) == 6:
|
| 3326 |
+
c+="1"
|
| 3327 |
+
else :
|
| 3328 |
+
c+="0"
|
| 3329 |
;;;
|
| 3330 |
+
(T) est un palindrome bis
|
| 3331 |
;;;
|
| 3332 |
3
|
| 3333 |
;;;
|
|
|
|
| 3377 |
>>> nombre_voyelles("Bonjour")
|
| 3378 |
3
|
| 3379 |
>>> nombre_voyelles("Python")
|
| 3380 |
+
2
|
| 3381 |
>>> nombre_voyelles("AEIOUY")
|
| 3382 |
6
|
| 3383 |
>>> nombre_voyelles("")
|
|
|
|
| 3401 |
c += "1"
|
| 3402 |
else:
|
| 3403 |
c += "0"
|
| 3404 |
+
if nombre_voyelles('z') == 0:
|
| 3405 |
+
c += '1'
|
| 3406 |
+
else:
|
| 3407 |
+
c += '0'
|
| 3408 |
;;;
|
| 3409 |
est un triangle rectangle ?
|
| 3410 |
;;;
|
|
|
|
| 3437 |
else:
|
| 3438 |
c += "0"
|
| 3439 |
;;;
|
| 3440 |
+
somme pairs
|
| 3441 |
+
;;;
|
| 3442 |
+
2
|
| 3443 |
+
;;;
|
| 3444 |
+
tableau, boucle for, parcours d'un tableau, conditions, modulo
|
| 3445 |
+
;;;
|
| 3446 |
+
Écrire une fonction `somme_pairs` qui prend en paramètre un tableau d'entiers `tab` et qui renvoie la somme de tous les nombres pairs présents dans le tableau. Si le tableau ne contient aucun nombre pair ou est vide, la fonction renvoie 0.
|
| 3447 |
+
Exemples :
|
| 3448 |
+
```
|
| 3449 |
+
>>> somme_pairs([1, 2, 3, 4])
|
| 3450 |
+
6
|
| 3451 |
+
>>> somme_pairs([1, 3, 5])
|
| 3452 |
+
0
|
| 3453 |
+
>>> somme_pairs([])
|
| 3454 |
+
0
|
| 3455 |
+
```
|
| 3456 |
+
;;;
|
| 3457 |
+
c = ""
|
| 3458 |
+
if somme_pairs([1, 2, 3, 4]) == 6:
|
| 3459 |
+
c += "1"
|
| 3460 |
+
else:
|
| 3461 |
+
c += "0"
|
| 3462 |
+
if somme_pairs([1, 3, 5]) == 0:
|
| 3463 |
+
c += "1"
|
| 3464 |
+
else:
|
| 3465 |
+
c += "0"
|
| 3466 |
+
if somme_pairs([]) == 0:
|
| 3467 |
+
c += "1"
|
| 3468 |
+
else:
|
| 3469 |
+
c += "0"
|
| 3470 |
+
;;;
|
| 3471 |
+
tous positifs
|
| 3472 |
+
;;;
|
| 3473 |
+
2
|
| 3474 |
+
;;;
|
| 3475 |
+
tableau, boucle for, booléen, conditions
|
| 3476 |
+
;;;
|
| 3477 |
+
Écrire une fonction `tous_positifs` qui prend en paramètre un tableau de nombres entiers `tab` et qui renvoie `True` si tous les éléments du tableau sont strictement positifs et `False` sinon. Un tableau vide doit renvoyer `True`.
|
| 3478 |
+
Exemples :
|
| 3479 |
+
```
|
| 3480 |
+
>>> tous_positifs([1, 5, 2, 9])
|
| 3481 |
+
True
|
| 3482 |
+
>>> tous_positifs([1, -3, 5])
|
| 3483 |
+
False
|
| 3484 |
+
>>> tous_positifs([])
|
| 3485 |
+
True
|
| 3486 |
+
```
|
| 3487 |
+
;;;
|
| 3488 |
+
c = ""
|
| 3489 |
+
if tous_positifs([1, 5, 2, 9]) == True:
|
| 3490 |
+
c += "1"
|
| 3491 |
+
else:
|
| 3492 |
+
c += "0"
|
| 3493 |
+
if tous_positifs([1, -3, 5]) == False:
|
| 3494 |
+
c += "1"
|
| 3495 |
+
else:
|
| 3496 |
+
c += "0"
|
| 3497 |
+
if tous_positifs([]) == True:
|
| 3498 |
+
c += "1"
|
| 3499 |
+
else:
|
| 3500 |
+
c += "0"
|
| 3501 |
+
;;;
|
| 3502 |
+
recherche arriere
|
| 3503 |
+
;;;
|
| 3504 |
+
2
|
| 3505 |
+
;;;
|
| 3506 |
+
tableau, parcours à l'envers, boucle for, indice
|
| 3507 |
+
;;;
|
| 3508 |
+
Écrire une fonction `recherche_arriere` qui prend en paramètres un tableau d'entiers `tab` et un entier `n`. La fonction renvoie l'indice de la dernière occurrence de `n` dans `tab`. Si `n` n'est pas présent, la fonction renvoie `None`.
|
| 3509 |
+
Exemples :
|
| 3510 |
+
```
|
| 3511 |
+
>>> recherche_arriere([1, 2, 3, 2, 4], 2)
|
| 3512 |
+
3
|
| 3513 |
+
>>> recherche_arriere([5, 5, 5], 5)
|
| 3514 |
+
2
|
| 3515 |
+
>>> recherche_arriere([1, 2], 3)
|
| 3516 |
+
None
|
| 3517 |
+
```
|
| 3518 |
+
;;;
|
| 3519 |
+
c = ""
|
| 3520 |
+
if recherche_arriere([1, 2, 3, 2, 4], 2) == 3:
|
| 3521 |
+
c += "1"
|
| 3522 |
+
else:
|
| 3523 |
+
c += "0"
|
| 3524 |
+
if recherche_arriere([5, 5, 5], 5) == 2:
|
| 3525 |
+
c += "1"
|
| 3526 |
+
else:
|
| 3527 |
+
c += "0"
|
| 3528 |
+
if recherche_arriere([1, 2], 3) == None:
|
| 3529 |
+
c += "1"
|
| 3530 |
+
else:
|
| 3531 |
+
c += "0"
|
| 3532 |
+
if recherche_arriere([1, 2, 3], 2) == 1:
|
| 3533 |
+
c += '1'
|
| 3534 |
+
else:
|
| 3535 |
+
c += '0'
|
| 3536 |
+
if recherche_arriere([10, 20, 30], 20) == 1:
|
| 3537 |
+
c += "1"
|
| 3538 |
+
else :
|
| 3539 |
+
c += "0"
|
| 3540 |
+
;;;
|
| 3541 |
+
produit tableau
|
| 3542 |
+
;;;
|
| 3543 |
+
2
|
| 3544 |
+
;;;
|
| 3545 |
+
tableau, boucle for, multiplication, accumulateur
|
| 3546 |
+
;;;
|
| 3547 |
+
Écrire une fonction `produit_tableau` qui prend en paramètre un tableau non vide de nombres entiers `tab` et renvoie le produit de tous ses éléments.
|
| 3548 |
+
Exemples :
|
| 3549 |
+
```
|
| 3550 |
+
>>> produit_tableau([2, 3, 4])
|
| 3551 |
+
24
|
| 3552 |
+
>>> produit_tableau([-1, 50])
|
| 3553 |
+
-50
|
| 3554 |
+
>>> produit_tableau([100, 0, 5])
|
| 3555 |
+
0
|
| 3556 |
+
```
|
| 3557 |
+
;;;
|
| 3558 |
+
c = ""
|
| 3559 |
+
if produit_tableau([2, 3, 4]) == 24:
|
| 3560 |
+
c += "1"
|
| 3561 |
+
else:
|
| 3562 |
+
c += "0"
|
| 3563 |
+
if produit_tableau([-1, 50]) == -50:
|
| 3564 |
+
c += "1"
|
| 3565 |
+
else:
|
| 3566 |
+
c += "0"
|
| 3567 |
+
if produit_tableau([100, 0, 5]) == 0:
|
| 3568 |
+
c += "1"
|
| 3569 |
+
else:
|
| 3570 |
+
c += "0"
|
| 3571 |
+
;;;
|
| 3572 |
+
compte voyelles
|
| 3573 |
+
;;;
|
| 3574 |
+
2
|
| 3575 |
+
;;;
|
| 3576 |
+
chaine de caractères, boucle for, test d'appartenance
|
| 3577 |
+
;;;
|
| 3578 |
+
Écrire une fonction `compte_voyelles` qui prend en paramètre une chaîne de caractères `mot` (contenant uniquement des lettres en minuscules) et renvoie le nombre de voyelles (a, e, i, o, u, y) qu'elle contient.
|
| 3579 |
+
Exemples :
|
| 3580 |
+
```
|
| 3581 |
+
>>> compte_voyelles("bonjour")
|
| 3582 |
+
3
|
| 3583 |
+
>>> compte_voyelles("rythme")
|
| 3584 |
+
1
|
| 3585 |
+
>>> compte_voyelles("bcdfg")
|
| 3586 |
+
0
|
| 3587 |
+
```
|
| 3588 |
+
;;;
|
| 3589 |
+
c = ""
|
| 3590 |
+
if compte_voyelles("bonjour") == 3:
|
| 3591 |
+
c += "1"
|
| 3592 |
+
else:
|
| 3593 |
+
c += "0"
|
| 3594 |
+
if compte_voyelles("rythme") == 1:
|
| 3595 |
+
c += "1"
|
| 3596 |
+
else:
|
| 3597 |
+
c += "0"
|
| 3598 |
+
if compte_voyelles("bcdfg") == 0:
|
| 3599 |
+
c += "1"
|
| 3600 |
+
else:
|
| 3601 |
+
c += "0"
|
| 3602 |
+
if compte_voyelles('z') == 0:
|
| 3603 |
+
c += '1'
|
| 3604 |
+
else:
|
| 3605 |
+
c += '0'
|
| 3606 |
+
;;;
|
| 3607 |
+
renverse tableau
|
| 3608 |
+
;;;
|
| 3609 |
+
2
|
| 3610 |
+
;;;
|
| 3611 |
+
tableau, parcours, création de tableau
|
| 3612 |
+
;;;
|
| 3613 |
+
Écrire une fonction `renverse_tableau` qui prend en paramètre un tableau `tab` et renvoie un NOUVEAU tableau contenant les mêmes éléments mais dans l'ordre inverse. Il est interdit d'utiliser la méthode `reverse` de Python ou les slices comme `[::-1]`.
|
| 3614 |
+
Exemples :
|
| 3615 |
+
```
|
| 3616 |
+
>>> renverse_tableau([1, 2, 3])
|
| 3617 |
+
[3, 2, 1]
|
| 3618 |
+
>>> renverse_tableau(["a", "b"])
|
| 3619 |
+
['b', 'a']
|
| 3620 |
+
>>> renverse_tableau([])
|
| 3621 |
+
[]
|
| 3622 |
+
```
|
| 3623 |
+
;;;
|
| 3624 |
+
c = ""
|
| 3625 |
+
if renverse_tableau([1, 2, 3]) == [3, 2, 1]:
|
| 3626 |
+
c += "1"
|
| 3627 |
+
else:
|
| 3628 |
+
c += "0"
|
| 3629 |
+
if renverse_tableau(["a", "b"]) == ["b", "a"]:
|
| 3630 |
+
c += "1"
|
| 3631 |
+
else:
|
| 3632 |
+
c += "0"
|
| 3633 |
+
if renverse_tableau([]) == []:
|
| 3634 |
+
c += "1"
|
| 3635 |
+
else:
|
| 3636 |
+
c += "0"
|
| 3637 |
+
;;;
|
| 3638 |
+
deuxieme plus grand
|
| 3639 |
+
;;;
|
| 3640 |
+
2
|
| 3641 |
+
;;;
|
| 3642 |
+
tableau, boucle for, comparaisons
|
| 3643 |
+
;;;
|
| 3644 |
+
Écrire une fonction `deuxieme_plus_grand` qui prend en paramètre un tableau non vide d'entiers distincts `tab` (contenant au moins deux éléments) et qui renvoie la valeur du deuxième plus grand élément. Il est interdit d'utiliser la méthode `sort` ou les fonctions `sorted` et `max`.
|
| 3645 |
+
Exemples :
|
| 3646 |
+
```
|
| 3647 |
+
>>> deuxieme_plus_grand([5, 20, 10, 15])
|
| 3648 |
+
15
|
| 3649 |
+
>>> deuxieme_plus_grand([-5, -10, -2])
|
| 3650 |
+
-5
|
| 3651 |
+
>>> deuxieme_plus_grand([1, 2])
|
| 3652 |
+
1
|
| 3653 |
+
```
|
| 3654 |
+
;;;
|
| 3655 |
+
c = ""
|
| 3656 |
+
if deuxieme_plus_grand([5, 20, 10, 15]) == 15:
|
| 3657 |
+
c += "1"
|
| 3658 |
+
else:
|
| 3659 |
+
c += "0"
|
| 3660 |
+
if deuxieme_plus_grand([-5, -10, -2]) == -5:
|
| 3661 |
+
c += "1"
|
| 3662 |
+
else:
|
| 3663 |
+
c += "0"
|
| 3664 |
+
if deuxieme_plus_grand([1, 2]) == 1:
|
| 3665 |
+
c += "1"
|
| 3666 |
+
else:
|
| 3667 |
+
c += "0"
|
| 3668 |
+
;;;
|
| 3669 |
+
filtre pairs
|
| 3670 |
+
;;;
|
| 3671 |
+
2
|
| 3672 |
+
;;;
|
| 3673 |
+
tableau, boucle for, conditions, création de tableau
|
| 3674 |
+
;;;
|
| 3675 |
+
Écrire une fonction `filtre_pairs` qui prend en paramètre un tableau d'entiers `tab` et renvoie un nouveau tableau contenant uniquement les nombres pairs de `tab` dans leur ordre d'apparition.
|
| 3676 |
+
Exemples :
|
| 3677 |
+
```
|
| 3678 |
+
>>> filtre_pairs([1, 2, 3, 4, 5])
|
| 3679 |
+
[2, 4]
|
| 3680 |
+
>>> filtre_pairs([1, 3, 5])
|
| 3681 |
+
[]
|
| 3682 |
+
>>> filtre_pairs([2, -4, 6])
|
| 3683 |
+
[2, -4, 6]
|
| 3684 |
+
```
|
| 3685 |
+
;;;
|
| 3686 |
+
c = ""
|
| 3687 |
+
if filtre_pairs([1, 2, 3, 4, 5]) == [2, 4]:
|
| 3688 |
+
c += "1"
|
| 3689 |
+
else:
|
| 3690 |
+
c += "0"
|
| 3691 |
+
if filtre_pairs([1, 3, 5]) == []:
|
| 3692 |
+
c += "1"
|
| 3693 |
+
else:
|
| 3694 |
+
c += "0"
|
| 3695 |
+
if filtre_pairs([2, -4, 6]) == [2, -4, 6]:
|
| 3696 |
+
c += "1"
|
| 3697 |
+
else:
|
| 3698 |
+
c += "0"
|
| 3699 |
+
;;;
|
| 3700 |
+
est parfait
|
| 3701 |
+
;;;
|
| 3702 |
+
2
|
| 3703 |
+
;;;
|
| 3704 |
+
mathématiques, boucle for, accumulateur, division
|
| 3705 |
+
;;;
|
| 3706 |
+
Écrire une fonction `est_parfait` qui prend en paramètre un entier strictement positif `n` et renvoie `True` si cet entier est un nombre parfait (c'est-à-dire égal à la somme de ses diviseurs propres strictements inférieurs à `n`), et `False` sinon.
|
| 3707 |
+
Exemples :
|
| 3708 |
+
```
|
| 3709 |
+
>>> est_parfait(6)
|
| 3710 |
+
True
|
| 3711 |
+
>>> est_parfait(28)
|
| 3712 |
+
True
|
| 3713 |
+
>>> est_parfait(10)
|
| 3714 |
+
False
|
| 3715 |
+
```
|
| 3716 |
+
;;;
|
| 3717 |
+
c = ""
|
| 3718 |
+
if est_parfait(6) == True:
|
| 3719 |
+
c += "1"
|
| 3720 |
+
else:
|
| 3721 |
+
c += "0"
|
| 3722 |
+
if est_parfait(28) == True:
|
| 3723 |
+
c += "1"
|
| 3724 |
+
else:
|
| 3725 |
+
c += "0"
|
| 3726 |
+
if est_parfait(10) == False:
|
| 3727 |
+
c += "1"
|
| 3728 |
+
else:
|
| 3729 |
+
c += "0"
|
| 3730 |
+
;;;
|
| 3731 |
+
alternance
|
| 3732 |
+
;;;
|
| 3733 |
+
2
|
| 3734 |
+
;;;
|
| 3735 |
+
tableau, boucle for, modulo, indice
|
| 3736 |
+
;;;
|
| 3737 |
+
Écrire une fonction `alternance` qui prend en paramètre un tableau non vide d'entiers `tab` et renvoie `True` si les éléments du tableau alternent strictement entre pair et impair (ou impair et pair), et `False` sinon. (Un tableau à 1 élément renvoie `True`).
|
| 3738 |
+
Exemples :
|
| 3739 |
+
```
|
| 3740 |
+
>>> alternance([1, 2, 3, 4])
|
| 3741 |
+
True
|
| 3742 |
+
>>> alternance([2, 5, 8, 11])
|
| 3743 |
+
True
|
| 3744 |
+
>>> alternance([1, 3, 2])
|
| 3745 |
+
False
|
| 3746 |
+
```
|
| 3747 |
+
;;;
|
| 3748 |
+
c = ""
|
| 3749 |
+
if alternance([1, 2, 3, 4]) == True:
|
| 3750 |
+
c += "1"
|
| 3751 |
+
else:
|
| 3752 |
+
c += "0"
|
| 3753 |
+
if alternance([2, 5, 8, 11]) == True:
|
| 3754 |
+
c += "1"
|
| 3755 |
+
else:
|
| 3756 |
+
c += "0"
|
| 3757 |
+
if alternance([1, 3, 2]) == False:
|
| 3758 |
+
c += "1"
|
| 3759 |
+
else:
|
| 3760 |
+
c += "0"
|
| 3761 |
+
;;;
|
| 3762 |
+
remplace
|
| 3763 |
+
;;;
|
| 3764 |
+
2
|
| 3765 |
+
;;;
|
| 3766 |
+
chaine de caractères, boucle for, concaténation
|
| 3767 |
+
;;;
|
| 3768 |
+
Écrire une fonction `remplace` qui prend en paramètres une chaîne de caractères `texte`, un caractère `c1` et un caractère `c2`. La fonction renvoie une nouvelle chaîne où toutes les occurrences de `c1` dans `texte` ont été remplacées par `c2`. L'utilisation de la méthode native `replace` est interdite.
|
| 3769 |
+
Exemples :
|
| 3770 |
+
```
|
| 3771 |
+
>>> remplace("bonjour", "o", "a")
|
| 3772 |
+
'banjaur'
|
| 3773 |
+
>>> remplace("test", "z", "e")
|
| 3774 |
+
'test'
|
| 3775 |
+
>>> remplace("", "a", "b")
|
| 3776 |
+
''
|
| 3777 |
+
```
|
| 3778 |
+
;;;
|
| 3779 |
+
c = ""
|
| 3780 |
+
if remplace("bonjour", "o", "a") == "banjaur":
|
| 3781 |
+
c += "1"
|
| 3782 |
+
else:
|
| 3783 |
+
c += "0"
|
| 3784 |
+
if remplace("test", "z", "e") == "test":
|
| 3785 |
+
c += "1"
|
| 3786 |
+
else:
|
| 3787 |
+
c += "0"
|
| 3788 |
+
if remplace("", "a", "b") == "":
|
| 3789 |
+
c += "1"
|
| 3790 |
+
else:
|
| 3791 |
+
c += "0"
|
| 3792 |
+
;;;
|
| 3793 |
+
est trie decroissant
|
| 3794 |
+
;;;
|
| 3795 |
+
2
|
| 3796 |
+
;;;
|
| 3797 |
+
tableau, boucle for, comparaisons
|
| 3798 |
+
;;;
|
| 3799 |
+
Écrire une fonction `est_trie_decroissant` qui prend en paramètre un tableau de nombres `tab` et renvoie `True` si le tableau est trié dans l'ordre décroissant, et `False` sinon. Un tableau vide ou ne contenant qu'un élément est considéré comme trié.
|
| 3800 |
+
Exemples :
|
| 3801 |
+
```
|
| 3802 |
+
>>> est_trie_decroissant([9, 5, 2, 1])
|
| 3803 |
+
True
|
| 3804 |
+
>>> est_trie_decroissant([5, 5, 3])
|
| 3805 |
+
True
|
| 3806 |
+
>>> est_trie_decroissant([10, 8, 12])
|
| 3807 |
+
False
|
| 3808 |
+
```
|
| 3809 |
+
;;;
|
| 3810 |
+
c = ""
|
| 3811 |
+
if est_trie_decroissant([9, 5, 2, 1]) == True:
|
| 3812 |
+
c += "1"
|
| 3813 |
+
else:
|
| 3814 |
+
c += "0"
|
| 3815 |
+
if est_trie_decroissant([5, 5, 3]) == True:
|
| 3816 |
+
c += "1"
|
| 3817 |
+
else:
|
| 3818 |
+
c += "0"
|
| 3819 |
+
if est_trie_decroissant([10, 8, 12]) == False:
|
| 3820 |
+
c += "1"
|
| 3821 |
+
else:
|
| 3822 |
+
c += "0"
|
| 3823 |
+
;;;
|
| 3824 |
+
ecart max
|
| 3825 |
+
;;;
|
| 3826 |
+
2
|
| 3827 |
+
;;;
|
| 3828 |
+
tableau, recherche minimum et maximum, soustraction
|
| 3829 |
+
;;;
|
| 3830 |
+
Écrire une fonction `ecart_max` qui prend en paramètre un tableau non vide de nombres `tab` et renvoie l'écart maximum entre deux valeurs du tableau (c'est-à-dire la différence entre la plus grande et la plus petite valeur). L'utilisation des fonctions natives `min` et `max` est interdite.
|
| 3831 |
+
Exemples :
|
| 3832 |
+
```
|
| 3833 |
+
>>> ecart_max([1, 5, 10, 2])
|
| 3834 |
+
9
|
| 3835 |
+
>>> ecart_max([-5, 0, 5])
|
| 3836 |
+
10
|
| 3837 |
+
>>> ecart_max([3, 3, 3])
|
| 3838 |
+
0
|
| 3839 |
+
```
|
| 3840 |
+
;;;
|
| 3841 |
+
c = ""
|
| 3842 |
+
if ecart_max([1, 5, 10, 2]) == 9:
|
| 3843 |
+
c += "1"
|
| 3844 |
+
else:
|
| 3845 |
+
c += "0"
|
| 3846 |
+
if ecart_max([-5, 0, 5]) == 10:
|
| 3847 |
+
c += "1"
|
| 3848 |
+
else:
|
| 3849 |
+
c += "0"
|
| 3850 |
+
if ecart_max([3, 3, 3]) == 0:
|
| 3851 |
+
c += "1"
|
| 3852 |
+
else:
|
| 3853 |
+
c += "0"
|
| 3854 |
+
if ecart_max([1, 2, 10, 3]) == 9:
|
| 3855 |
+
c += '1'
|
| 3856 |
+
else:
|
| 3857 |
+
c += '0'
|
| 3858 |
+
if ecart_max([42, 17, 99]) == 82:
|
| 3859 |
+
c += "1"
|
| 3860 |
+
else :
|
| 3861 |
+
c += "0"
|
| 3862 |
+
;;;
|
| 3863 |
+
intersection tableaux
|
| 3864 |
+
;;;
|
| 3865 |
+
2
|
| 3866 |
+
;;;
|
| 3867 |
+
tableau, boucle for, test d'appartenance
|
| 3868 |
+
;;;
|
| 3869 |
+
Écrire une fonction `intersection` qui prend en paramètres deux tableaux d'entiers `tab1` et `tab2` sans doublons et qui renvoie un nouveau tableau contenant les éléments présents à la fois dans `tab1` et `tab2`, dans leur ordre d'apparition dans `tab1`.
|
| 3870 |
+
Exemples :
|
| 3871 |
+
```
|
| 3872 |
+
>>> intersection([1, 2, 3], [2, 3, 4])
|
| 3873 |
+
[2, 3]
|
| 3874 |
+
>>> intersection([1, 5, 9, 2], [5, 2, 8])
|
| 3875 |
+
[5, 2]
|
| 3876 |
+
>>> intersection([1, 2], [3, 4])
|
| 3877 |
+
[]
|
| 3878 |
+
```
|
| 3879 |
+
;;;
|
| 3880 |
+
c = ""
|
| 3881 |
+
if intersection([1, 2, 3], [2, 3, 4]) == [2, 3]:
|
| 3882 |
+
c += "1"
|
| 3883 |
+
else:
|
| 3884 |
+
c += "0"
|
| 3885 |
+
if intersection([1, 5, 9, 2], [5, 2, 8]) == [5, 2]:
|
| 3886 |
+
c += "1"
|
| 3887 |
+
else:
|
| 3888 |
+
c += "0"
|
| 3889 |
+
if intersection([1, 2], [3, 4]) == []:
|
| 3890 |
+
c += "1"
|
| 3891 |
+
else:
|
| 3892 |
+
c += "0"
|
| 3893 |
+
;;;
|
| 3894 |
+
prefixes
|
| 3895 |
+
;;;
|
| 3896 |
+
2
|
| 3897 |
+
;;;
|
| 3898 |
+
chaine de caractères, boucle for, concaténation, tableau
|
| 3899 |
+
;;;
|
| 3900 |
+
Écrire une fonction `prefixes` qui prend en paramètre une chaîne de caractères `mot` et renvoie un tableau contenant tous les préfixes non vides de ce mot, du plus court au plus long.
|
| 3901 |
+
Exemples :
|
| 3902 |
+
```
|
| 3903 |
+
>>> prefixes("chat")
|
| 3904 |
+
['c', 'ch', 'cha', 'chat']
|
| 3905 |
+
>>> prefixes("a")
|
| 3906 |
+
['a']
|
| 3907 |
+
>>> prefixes("")
|
| 3908 |
+
[]
|
| 3909 |
+
```
|
| 3910 |
+
;;;
|
| 3911 |
+
c = ""
|
| 3912 |
+
if prefixes("chat") == ['c', 'ch', 'cha', 'chat']:
|
| 3913 |
+
c += "1"
|
| 3914 |
+
else:
|
| 3915 |
+
c += "0"
|
| 3916 |
+
if prefixes("a") == ['a']:
|
| 3917 |
+
c += "1"
|
| 3918 |
+
else:
|
| 3919 |
+
c += "0"
|
| 3920 |
+
if prefixes("") == []:
|
| 3921 |
+
c += "1"
|
| 3922 |
+
else:
|
| 3923 |
+
c += "0"
|
| 3924 |
+
;;;
|