Spaces:
Running
Running
Upload code.txt
Browse files
code.txt
CHANGED
|
@@ -24,6 +24,37 @@ if moyenne([8, 11, 17, 10]) == 11.5:
|
|
| 24 |
else :
|
| 25 |
c += "0"
|
| 26 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
maximum tableau
|
| 28 |
;;;
|
| 29 |
2
|
|
@@ -58,6 +89,37 @@ if maximum_tableau([-27, -24, -3, 15]) == 15:
|
|
| 58 |
else :
|
| 59 |
c += "0"
|
| 60 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
recherche
|
| 62 |
;;;
|
| 63 |
2
|
|
@@ -89,6 +151,69 @@ if recherche([2,3,5,2,4],2) == 0:
|
|
| 89 |
else :
|
| 90 |
c += "0"
|
| 91 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
max et indice
|
| 93 |
;;;
|
| 94 |
2
|
|
@@ -127,6 +252,65 @@ if max_et_indice([1, 1, 1, 1]) == (1, 0):
|
|
| 127 |
else :
|
| 128 |
c += "0"
|
| 129 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
verifie
|
| 131 |
;;;
|
| 132 |
3
|
|
@@ -171,6 +355,42 @@ if verifie([5]):
|
|
| 171 |
else :
|
| 172 |
c += "0"
|
| 173 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
premier et dernier
|
| 175 |
;;;
|
| 176 |
2
|
|
@@ -281,6 +501,31 @@ if tri_selection([6]) == [6]:
|
|
| 281 |
else :
|
| 282 |
c += "0"
|
| 283 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
min et max
|
| 285 |
;;;
|
| 286 |
2
|
|
@@ -356,6 +601,31 @@ if nb_repetitions(12, [1, 3, 7, 21, 36, 44]) == 0:
|
|
| 356 |
else :
|
| 357 |
c += "0"
|
| 358 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
recherche motif
|
| 360 |
;;;
|
| 361 |
3
|
|
@@ -433,6 +703,40 @@ if recherche_indices_classement(3, []) == ([], [], []):
|
|
| 433 |
else :
|
| 434 |
c+="0"
|
| 435 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
(T) parcours largeur arbre
|
| 437 |
;;;
|
| 438 |
3
|
|
|
|
| 24 |
else :
|
| 25 |
c += "0"
|
| 26 |
;;;
|
| 27 |
+
est voyelle
|
| 28 |
+
;;;
|
| 29 |
+
1
|
| 30 |
+
;;;
|
| 31 |
+
chaine de caractères, conditions, test d'appartenance
|
| 32 |
+
;;;
|
| 33 |
+
Écrire une fonction `est_voyelle` qui prend en paramètre une chaîne de caractères `lettre` contenant un seul caractère en minuscule, et qui renvoie `True` si cette lettre est une voyelle (a, e, i, o, u, y) et `False` sinon.
|
| 34 |
+
Exemples :
|
| 35 |
+
```
|
| 36 |
+
>>> est_voyelle('a')
|
| 37 |
+
True
|
| 38 |
+
>>> est_voyelle('b')
|
| 39 |
+
False
|
| 40 |
+
>>> est_voyelle('y')
|
| 41 |
+
True
|
| 42 |
+
```
|
| 43 |
+
;;;
|
| 44 |
+
c = ""
|
| 45 |
+
if est_voyelle('a') == True:
|
| 46 |
+
c += "1"
|
| 47 |
+
else:
|
| 48 |
+
c += "0"
|
| 49 |
+
if est_voyelle('b') == False:
|
| 50 |
+
c += "1"
|
| 51 |
+
else:
|
| 52 |
+
c += "0"
|
| 53 |
+
if est_voyelle('y') == True:
|
| 54 |
+
c += "1"
|
| 55 |
+
else:
|
| 56 |
+
c += "0"
|
| 57 |
+
;;;
|
| 58 |
maximum tableau
|
| 59 |
;;;
|
| 60 |
2
|
|
|
|
| 89 |
else :
|
| 90 |
c += "0"
|
| 91 |
;;;
|
| 92 |
+
mot de passe valide
|
| 93 |
+
;;;
|
| 94 |
+
1
|
| 95 |
+
;;;
|
| 96 |
+
chaine de caractères, longueur, conditions
|
| 97 |
+
;;;
|
| 98 |
+
Écrire une fonction `mdp_valide` qui prend en paramètre une chaîne de caractères `mot_de_passe` et renvoie `True` si celui-ci comporte au moins 8 caractères, et `False` sinon.
|
| 99 |
+
Exemples :
|
| 100 |
+
```
|
| 101 |
+
>>> mdp_valide('1234567')
|
| 102 |
+
False
|
| 103 |
+
>>> mdp_valide('12345678')
|
| 104 |
+
True
|
| 105 |
+
>>> mdp_valide('MonSuperMDP12')
|
| 106 |
+
True
|
| 107 |
+
```
|
| 108 |
+
;;;
|
| 109 |
+
c = ""
|
| 110 |
+
if mdp_valide('1234567') == False:
|
| 111 |
+
c += "1"
|
| 112 |
+
else:
|
| 113 |
+
c += "0"
|
| 114 |
+
if mdp_valide('12345678') == True:
|
| 115 |
+
c += "1"
|
| 116 |
+
else:
|
| 117 |
+
c += "0"
|
| 118 |
+
if mdp_valide('MonSuperMDP12') == True:
|
| 119 |
+
c += "1"
|
| 120 |
+
else:
|
| 121 |
+
c += "0"
|
| 122 |
+
;;;
|
| 123 |
recherche
|
| 124 |
;;;
|
| 125 |
2
|
|
|
|
| 151 |
else :
|
| 152 |
c += "0"
|
| 153 |
;;;
|
| 154 |
+
est bissextile
|
| 155 |
+
;;;
|
| 156 |
+
2
|
| 157 |
+
;;;
|
| 158 |
+
conditions, modulo, années
|
| 159 |
+
;;;
|
| 160 |
+
Écrire une fonction `est_bissextile` qui prend en paramètre un entier positif `annee` et qui renvoie `True` si l'année est bissextile, et `False` sinon.
|
| 161 |
+
Rappel : une année est bissextile si elle est divisible par 4 mais non divisible par 100. Les années divisibles par 400 sont également bissextiles.
|
| 162 |
+
Exemples :
|
| 163 |
+
```
|
| 164 |
+
>>> est_bissextile(2020)
|
| 165 |
+
True
|
| 166 |
+
>>> est_bissextile(2100)
|
| 167 |
+
False
|
| 168 |
+
>>> est_bissextile(2000)
|
| 169 |
+
True
|
| 170 |
+
```
|
| 171 |
+
;;;
|
| 172 |
+
c = ""
|
| 173 |
+
if est_bissextile(2020) == True:
|
| 174 |
+
c += "1"
|
| 175 |
+
else:
|
| 176 |
+
c += "0"
|
| 177 |
+
if est_bissextile(2100) == False:
|
| 178 |
+
c += "1"
|
| 179 |
+
else:
|
| 180 |
+
c += "0"
|
| 181 |
+
if est_bissextile(2000) == True:
|
| 182 |
+
c += "1"
|
| 183 |
+
else:
|
| 184 |
+
c += "0"
|
| 185 |
+
;;;
|
| 186 |
+
dernier chiffre
|
| 187 |
+
;;;
|
| 188 |
+
2
|
| 189 |
+
;;;
|
| 190 |
+
mathématiques, calculs, modulo 10
|
| 191 |
+
;;;
|
| 192 |
+
Écrire une fonction `dernier_chiffre` qui prend en paramètre un entier positif `n` et qui renvoie son dernier chiffre des unités.
|
| 193 |
+
Exemples :
|
| 194 |
+
```
|
| 195 |
+
>>> dernier_chiffre(145)
|
| 196 |
+
5
|
| 197 |
+
>>> dernier_chiffre(42)
|
| 198 |
+
2
|
| 199 |
+
>>> dernier_chiffre(1980)
|
| 200 |
+
0
|
| 201 |
+
```
|
| 202 |
+
;;;
|
| 203 |
+
c = ""
|
| 204 |
+
if dernier_chiffre(145) == 5:
|
| 205 |
+
c += "1"
|
| 206 |
+
else:
|
| 207 |
+
c += "0"
|
| 208 |
+
if dernier_chiffre(42) == 2:
|
| 209 |
+
c += "1"
|
| 210 |
+
else:
|
| 211 |
+
c += "0"
|
| 212 |
+
if dernier_chiffre(1980) == 0:
|
| 213 |
+
c += "1"
|
| 214 |
+
else:
|
| 215 |
+
c += "0"
|
| 216 |
+
;;;
|
| 217 |
max et indice
|
| 218 |
;;;
|
| 219 |
2
|
|
|
|
| 252 |
else :
|
| 253 |
c += "0"
|
| 254 |
;;;
|
| 255 |
+
tarification
|
| 256 |
+
;;;
|
| 257 |
+
1
|
| 258 |
+
;;;
|
| 259 |
+
conditions multiples, if, elif, else
|
| 260 |
+
;;;
|
| 261 |
+
Écrire une fonction `tarification` qui prend en paramètre un entier positif `age` et qui renvoie une chaîne de caractères correspondant au tarif du billet :
|
| 262 |
+
- "Gratuit" si l'âge est strictement inférieur à 4 ans.
|
| 263 |
+
- "Demi-tarif" si l'âge est compris entre 4 ans (inclus) et strictement inférieur à 12 ans.
|
| 264 |
+
- "Plein tarif" dans tous les autres cas.
|
| 265 |
+
Exemples :
|
| 266 |
+
```
|
| 267 |
+
>>> tarification(3)
|
| 268 |
+
'Gratuit'
|
| 269 |
+
>>> tarification(8)
|
| 270 |
+
'Demi-tarif'
|
| 271 |
+
>>> tarification(25)
|
| 272 |
+
'Plein tarif'
|
| 273 |
+
```
|
| 274 |
+
;;;
|
| 275 |
+
c = ""
|
| 276 |
+
if tarification(3) == 'Gratuit':
|
| 277 |
+
c += "1"
|
| 278 |
+
else:
|
| 279 |
+
c += "0"
|
| 280 |
+
if tarification(8) == 'Demi-tarif':
|
| 281 |
+
c += "1"
|
| 282 |
+
else:
|
| 283 |
+
c += "0"
|
| 284 |
+
if tarification(25) == 'Plein tarif':
|
| 285 |
+
c += "1"
|
| 286 |
+
else:
|
| 287 |
+
c += "0"
|
| 288 |
+
;;;
|
| 289 |
+
prix TTC
|
| 290 |
+
;;;
|
| 291 |
+
1
|
| 292 |
+
;;;
|
| 293 |
+
calculs, flottants, multiplication, addition
|
| 294 |
+
;;;
|
| 295 |
+
Écrire une fonction `prix_ttc` qui prend en paramètres d'abord un prix hors taxes `ht` (un nombre) puis un taux de TVA `taux` en pourcentage (un nombre). La fonction renvoie le prix toutes taxes comprises (TTC) final.
|
| 296 |
+
Exemples :
|
| 297 |
+
```
|
| 298 |
+
>>> prix_ttc(100, 20)
|
| 299 |
+
120.0
|
| 300 |
+
>>> prix_ttc(50, 5.5)
|
| 301 |
+
52.75
|
| 302 |
+
```
|
| 303 |
+
;;;
|
| 304 |
+
c = ""
|
| 305 |
+
if prix_ttc(100, 20) == 120.0:
|
| 306 |
+
c += "1"
|
| 307 |
+
else:
|
| 308 |
+
c += "0"
|
| 309 |
+
if prix_ttc(50, 5.5) == 52.75:
|
| 310 |
+
c += "1"
|
| 311 |
+
else:
|
| 312 |
+
c += "0"
|
| 313 |
+
;;;
|
| 314 |
verifie
|
| 315 |
;;;
|
| 316 |
3
|
|
|
|
| 355 |
else :
|
| 356 |
c += "0"
|
| 357 |
;;;
|
| 358 |
+
mention bac
|
| 359 |
+
;;;
|
| 360 |
+
1
|
| 361 |
+
;;;
|
| 362 |
+
conditions multiples, intervalles
|
| 363 |
+
;;;
|
| 364 |
+
Écrire une fonction `mention_bac` qui prend en paramètre une note `moyenne` sur 20 et renvoie une chaîne de caractères correspondant à la mention :
|
| 365 |
+
- "Très bien" pour une moyenne supérieure ou égale à 16.
|
| 366 |
+
- "Bien" pour une moyenne entre 14 (inclus) et 16 (exclu).
|
| 367 |
+
- "Assez bien" pour une moyenne entre 12 (inclus) et 14 (exclu).
|
| 368 |
+
- "Passable" pour une moyenne entre 10 (inclus) et 12 (exclu).
|
| 369 |
+
- "Recalé" si la moyenne est strictement inférieure à 10.
|
| 370 |
+
Exemples :
|
| 371 |
+
```
|
| 372 |
+
>>> mention_bac(16.5)
|
| 373 |
+
'Très bien'
|
| 374 |
+
>>> mention_bac(12)
|
| 375 |
+
'Assez bien'
|
| 376 |
+
>>> mention_bac(8.5)
|
| 377 |
+
'Recalé'
|
| 378 |
+
```
|
| 379 |
+
;;;
|
| 380 |
+
c = ""
|
| 381 |
+
if mention_bac(16.5) == 'Très bien':
|
| 382 |
+
c += "1"
|
| 383 |
+
else:
|
| 384 |
+
c += "0"
|
| 385 |
+
if mention_bac(12) == 'Assez bien':
|
| 386 |
+
c += "1"
|
| 387 |
+
else:
|
| 388 |
+
c += "0"
|
| 389 |
+
if mention_bac(8.5) == 'Recalé':
|
| 390 |
+
c += "1"
|
| 391 |
+
else:
|
| 392 |
+
c += "0"
|
| 393 |
+
;;;
|
| 394 |
premier et dernier
|
| 395 |
;;;
|
| 396 |
2
|
|
|
|
| 501 |
else :
|
| 502 |
c += "0"
|
| 503 |
;;;
|
| 504 |
+
salutation
|
| 505 |
+
;;;
|
| 506 |
+
1
|
| 507 |
+
;;;
|
| 508 |
+
chaine de caractères, concaténation, conditions
|
| 509 |
+
;;;
|
| 510 |
+
Écrire une fonction `salutation` qui prend en paramètres une chaîne de caractères `prenom` et un entier `heure` (compris entre 0 et 23). La fonction renvoie la chaîne "Bonjour [prenom]" si l'heure est strictement inférieure à 18, et "Bonsoir [prenom]" sinon. (Note : remplacez [prenom] par la valeur réelle).
|
| 511 |
+
Exemples :
|
| 512 |
+
```
|
| 513 |
+
>>> salutation("Alice", 14)
|
| 514 |
+
'Bonjour Alice'
|
| 515 |
+
>>> salutation("Bob", 20)
|
| 516 |
+
'Bonsoir Bob'
|
| 517 |
+
```
|
| 518 |
+
;;;
|
| 519 |
+
c = ""
|
| 520 |
+
if salutation("Alice", 14) == 'Bonjour Alice':
|
| 521 |
+
c += "1"
|
| 522 |
+
else:
|
| 523 |
+
c += "0"
|
| 524 |
+
if salutation("Bob", 20) == 'Bonsoir Bob':
|
| 525 |
+
c += "1"
|
| 526 |
+
else:
|
| 527 |
+
c += "0"
|
| 528 |
+
;;;
|
| 529 |
min et max
|
| 530 |
;;;
|
| 531 |
2
|
|
|
|
| 601 |
else :
|
| 602 |
c += "0"
|
| 603 |
;;;
|
| 604 |
+
volume cube
|
| 605 |
+
;;;
|
| 606 |
+
1
|
| 607 |
+
;;;
|
| 608 |
+
géométrie, calculs, puissance, 3D
|
| 609 |
+
;;;
|
| 610 |
+
Écrire une fonction `volume_cube` qui prend en paramètre un nombre positif `arete` et qui renvoie le volume du cube correspondant.
|
| 611 |
+
Exemples :
|
| 612 |
+
```
|
| 613 |
+
>>> volume_cube(3)
|
| 614 |
+
27
|
| 615 |
+
>>> volume_cube(10)
|
| 616 |
+
1000
|
| 617 |
+
```
|
| 618 |
+
;;;
|
| 619 |
+
c = ""
|
| 620 |
+
if volume_cube(3) == 27:
|
| 621 |
+
c += "1"
|
| 622 |
+
else:
|
| 623 |
+
c += "0"
|
| 624 |
+
if volume_cube(10) == 1000:
|
| 625 |
+
c += "1"
|
| 626 |
+
else:
|
| 627 |
+
c += "0"
|
| 628 |
+
;;;
|
| 629 |
recherche motif
|
| 630 |
;;;
|
| 631 |
3
|
|
|
|
| 703 |
else :
|
| 704 |
c+="0"
|
| 705 |
;;;
|
| 706 |
+
signe
|
| 707 |
+
;;;
|
| 708 |
+
1
|
| 709 |
+
;;;
|
| 710 |
+
conditions multiples, zéro
|
| 711 |
+
;;;
|
| 712 |
+
Écrire une fonction `signe` qui prend en paramètre un entier `n` et renvoie une chaîne de caractères :
|
| 713 |
+
- "strictement positif" si le nombre est supérieur à zéro.
|
| 714 |
+
- "strictement négatif" si le nombre est inférieur à zéro.
|
| 715 |
+
- "nul" si le nombre est égal à zéro.
|
| 716 |
+
Exemples :
|
| 717 |
+
```
|
| 718 |
+
>>> signe(42)
|
| 719 |
+
'strictement positif'
|
| 720 |
+
>>> signe(-5)
|
| 721 |
+
'strictement négatif'
|
| 722 |
+
>>> signe(0)
|
| 723 |
+
'nul'
|
| 724 |
+
```
|
| 725 |
+
;;;
|
| 726 |
+
c = ""
|
| 727 |
+
if signe(42) == 'strictement positif':
|
| 728 |
+
c += "1"
|
| 729 |
+
else:
|
| 730 |
+
c += "0"
|
| 731 |
+
if signe(-5) == 'strictement négatif':
|
| 732 |
+
c += "1"
|
| 733 |
+
else:
|
| 734 |
+
c += "0"
|
| 735 |
+
if signe(0) == 'nul':
|
| 736 |
+
c += "1"
|
| 737 |
+
else:
|
| 738 |
+
c += "0"
|
| 739 |
+
;;;
|
| 740 |
(T) parcours largeur arbre
|
| 741 |
;;;
|
| 742 |
3
|