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0"
|
| 2762 |
;;;
|
| 2763 |
+
somme des nombres pairs d'un tableau
|
| 2764 |
+
;;;
|
| 2765 |
+
2
|
| 2766 |
+
;;;
|
| 2767 |
+
tableau (liste Python), boucle for, condition (if), modulo, somme
|
| 2768 |
+
;;;
|
| 2769 |
+
Écrire une fonction `somme_pairs` qui prend en paramètre un tableau d'entiers tab (type list) et qui renvoie la somme des nombres pairs contenus dans ce tableau.
|
| 2770 |
+
Si le tableau est vide, la fonction doit retourner 0.
|
| 2771 |
+
Exemples :
|
| 2772 |
+
```
|
| 2773 |
+
>>> somme_pairs([1, 2, 3, 4, 5, 6])
|
| 2774 |
+
12
|
| 2775 |
+
>>> somme_pairs([1, 3, 5, 7])
|
| 2776 |
+
0
|
| 2777 |
+
>>> somme_pairs([2, 4, 6, 8])
|
| 2778 |
+
20
|
| 2779 |
+
>>> somme_pairs([])
|
| 2780 |
+
0
|
| 2781 |
+
```
|
| 2782 |
+
;;;
|
| 2783 |
+
c = ""
|
| 2784 |
+
if somme_pairs([1, 2, 3, 4, 5, 6]) == 12:
|
| 2785 |
+
c += "1"
|
| 2786 |
+
else:
|
| 2787 |
+
c += "0"
|
| 2788 |
+
if somme_pairs([1, 3, 5, 7]) == 0:
|
| 2789 |
+
c += "1"
|
| 2790 |
+
else:
|
| 2791 |
+
c += "0"
|
| 2792 |
+
if somme_pairs([2, 4, 6, 8]) == 20:
|
| 2793 |
+
c += "1"
|
| 2794 |
+
else:
|
| 2795 |
+
c += "0"
|
| 2796 |
+
if somme_pairs([]) == 0:
|
| 2797 |
+
c += "1"
|
| 2798 |
+
else:
|
| 2799 |
+
c += "0"
|
| 2800 |
+
;;;
|
| 2801 |
+
est un palindrome bis (T)
|
| 2802 |
+
;;;
|
| 2803 |
+
3
|
| 2804 |
+
;;;
|
| 2805 |
+
chaine de caractères, parcours d'une chaine, récursivité
|
| 2806 |
+
;;;
|
| 2807 |
+
Écrire une fonction récursive `est_palindrome_recursive` qui prend en paramètre une chaîne de caractères `mot` et qui renvoie `True` si `mot` est un palindrome, et `False` sinon.
|
| 2808 |
+
Un mot est un palindrome s'il se lit de la même manière de gauche à droite et de droite à gauche.
|
| 2809 |
+
Exemples :
|
| 2810 |
+
```
|
| 2811 |
+
>>> est_palindrome_recursive("radar")
|
| 2812 |
+
True
|
| 2813 |
+
>>> est_palindrome_recursive("python")
|
| 2814 |
+
False
|
| 2815 |
+
>>> est_palindrome_recursive("")
|
| 2816 |
+
True
|
| 2817 |
+
>>> est_palindrome_recursive("a")
|
| 2818 |
+
True
|
| 2819 |
+
```
|
| 2820 |
+
;;;
|
| 2821 |
+
c = ""
|
| 2822 |
+
if est_palindrome_recursive("radar"):
|
| 2823 |
+
c += "1"
|
| 2824 |
+
else:
|
| 2825 |
+
c += "0"
|
| 2826 |
+
if not est_palindrome_recursive("python"):
|
| 2827 |
+
c += "1"
|
| 2828 |
+
else:
|
| 2829 |
+
c += "0"
|
| 2830 |
+
if est_palindrome_recursive(""):
|
| 2831 |
+
c += "1"
|
| 2832 |
+
else:
|
| 2833 |
+
c += "0"
|
| 2834 |
+
if est_palindrome_recursive("a"):
|
| 2835 |
+
c += "1"
|
| 2836 |
+
else:
|
| 2837 |
+
c += "0"
|
| 2838 |
+
;;;
|
| 2839 |
+
trouve le nombre de voyelles dans une chaine de caractères
|
| 2840 |
+
;;;
|
| 2841 |
+
2
|
| 2842 |
+
;;;
|
| 2843 |
+
chaine de caractères, boucle for, test d'appartenance
|
| 2844 |
+
;;;
|
| 2845 |
+
Écrire une fonction `nombre_voyelles` qui prend en paramètre une chaîne de caractères `chaine` et qui renvoie le nombre de voyelles (a, e, i, o, u, y) présentes dans la chaîne. La casse (majuscules/minuscules) ne doit pas être prise en compte.
|
| 2846 |
+
Exemples :
|
| 2847 |
+
```
|
| 2848 |
+
>>> nombre_voyelles("Bonjour")
|
| 2849 |
+
3
|
| 2850 |
+
>>> nombre_voyelles("Python")
|
| 2851 |
+
1
|
| 2852 |
+
>>> nombre_voyelles("AEIOUY")
|
| 2853 |
+
6
|
| 2854 |
+
>>> nombre_voyelles("")
|
| 2855 |
+
0
|
| 2856 |
+
```
|
| 2857 |
+
;;;
|
| 2858 |
+
c = ""
|
| 2859 |
+
if nombre_voyelles("Bonjour") == 3:
|
| 2860 |
+
c += "1"
|
| 2861 |
+
else:
|
| 2862 |
+
c += "0"
|
| 2863 |
+
if nombre_voyelles("Python") == 2:
|
| 2864 |
+
c += "1"
|
| 2865 |
+
else:
|
| 2866 |
+
c += "0"
|
| 2867 |
+
if nombre_voyelles("AEIOUY") == 6:
|
| 2868 |
+
c += "1"
|
| 2869 |
+
else:
|
| 2870 |
+
c += "0"
|
| 2871 |
+
if nombre_voyelles("") == 0:
|
| 2872 |
+
c += "1"
|
| 2873 |
+
else:
|
| 2874 |
+
c += "0"
|
| 2875 |
+
;;;
|
| 2876 |
+
est un triangle rectangle ?
|
| 2877 |
+
;;;
|
| 2878 |
+
2
|
| 2879 |
+
;;;
|
| 2880 |
+
test d'égalité, théorème de pythagore, calcul
|
| 2881 |
+
;;;
|
| 2882 |
+
Écrire une fonction `est_rectangle` qui prend en paramètre trois entiers `a`, `b` et `c`, représentant les longueurs des côtés d'un triangle. La fonction doit renvoyer `True` si le triangle est rectangle et `False sinon`. On suppose que `c` est la longueur du côté le plus grand.
|
| 2883 |
+
Exemples :
|
| 2884 |
+
```
|
| 2885 |
+
>>> est_rectangle(3, 4, 5)
|
| 2886 |
+
True
|
| 2887 |
+
>>> est_rectangle(5, 12, 13)
|
| 2888 |
+
True
|
| 2889 |
+
>>> est_rectangle(6, 8, 11)
|
| 2890 |
+
False
|
| 2891 |
+
```
|
| 2892 |
+
;;;
|
| 2893 |
+
c = ""
|
| 2894 |
+
if est_rectangle(3, 4, 5):
|
| 2895 |
+
c += "1"
|
| 2896 |
+
else:
|
| 2897 |
+
c += "0"
|
| 2898 |
+
if est_rectangle(5, 12, 13):
|
| 2899 |
+
c += "1"
|
| 2900 |
+
else:
|
| 2901 |
+
c += "0"
|
| 2902 |
+
if not est_rectangle(6, 8, 11):
|
| 2903 |
+
c += "1"
|
| 2904 |
+
else:
|
| 2905 |
+
c += "0"
|
| 2906 |
+
;;;
|