Exercices sur la base
« titanic »☘
Ces exercices doivent être utilisés pour vous entraîner à programmer. Ils sont généralement accompagnés d'aide et de leur solution pour vous permettre de progresser.
Avant de vous précipiter sur ces solutions dès la première difficulté, n'oubliez pas les conseils suivants :
- Avez-vous bien fait un schéma au brouillon pour visualiser le problème posé ?
- Avez-vous essayé de rédiger un algorithme en français, avec vos propres mots, avant de vous lancer dans la programmation sur machine ?
- Avez-vous utilisé des affichages intermédiaires, des
print()
, pour visualiser au fur et à mesure le contenu des variables ? - Avez-vous testé le programme avec les propositions de tests donnés dans l'exercice ?
- Avez-vous testé le programme avec de nouveaux tests, différents de ceux proposés ?
Attention
- Ne pas oublier de sauvegarder les fichiers dans le répertoire
[NSI_Tables_Donnees]
. - Ne pas oublier d'importer le module
fonctions_csv
. - Ne pas oublier d'importer les fichiers CSV en tableau de dictionnaires pour pouvoir utiliser les fonctions...
Dans ces exercices, on utilise le fichier titanic.csv, à télécharger et sauvegarder dans le répertoire de travail.
Ce fichier a été modifié pour que le séparateur de données soit la virgule (le séparateur de données d'origine était la tabulation).
Quelques explications sur cette base de données
Précisons la légende:
- PassengerId : identifiant du passager (on peut considérer par exemple qu'il s'agit de son numéro d'enregistrement, chaque passager a ainsi un identifiant différent de celui des autres passagers).
- Survived : 0 signifie que le passager n'a pas survécu à l'accident, 1 qu'il a survécu.
- Pclass : 1, 2 ou 3 (première classe, seconde classe ou troisième classe).
- Name : nom du passager.
- Sex.
- Age.
- SibSp : nombre de frères, soeurs (et conjoints) sur le bateau.
- Parch : nombre de parents et enfants sur le bateau.
- Ticket : numéro (code) du ticket passager.
- Fare : prix du ticket.
- Cabin : numéro de cabine.
- Embarked : Port d'embarcation (C = Cherbourg, Q = Queenstown, S = Southampton).
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22 | 1 | 0 | A/5 21171 | 7.25 | S | |
2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Thayer) | female | 38 | 1 | 0 | PC 17599 | 71.25 | C85 | C |
3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26 | 0 | 0 | STON/O2. 3101282 | 7.9 | S | |
4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35 | 1 | 0 | 113803 | 53.1 | C123 | S |
5 | 0 | 3 | Allen, Mr. William Henry | male | 35 | 0 | 0 | 373450 | 8.05 | S | |
6 | 0 | 3 | Moran, Mr. James | male | 43 | 0 | 0 | 330877 | 8.45 | Q | |
7 | 0 | 1 | McCarthy, Mr. Timothy J | male | 54 | 0 | 0 | 17463 | 51.86 | E46 | S |
8 | 0 | 3 | Palsson, Master. Gosta Leonard | male | 2 | 3 | 1 | 349909 | 21.07 | S | |
9 | 1 | 3 | Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) | female | 27 | 0 | 2 | 347742 | 11.13 | S | |
10 | 1 | 2 | Nasser, Mrs. Nicholas (Adele Achem) | female | 14 | 1 | 0 | 237736 | 30.07 | C | |
11 | 1 | 3 | Sandstrom, Miss. Marguerite Rut | female | 4 | 1 | 1 | PP 9549 | 16.7 | G6 | S |
12 | 1 | 1 | Bonnell, Miss. Elizabeth | female | 58 | 0 | 0 | 113783 | 26.55 | C103 | S |
13 | 0 | 3 | Saundercock, Mr. William Henry | male | 20 | 0 | 0 | A/5. 2151 | 8.05 | S | |
14 | 0 | 3 | Andersson, Mr. Anders Johan | male | 39 | 1 | 5 | 347082 | 31.27 | S | |
15 | 0 | 3 | Vestrom, Miss. Hulda Amanda Adolfina | female | 14 | 0 | 0 | 350406 | 7.85 | S | |
16 | 1 | 2 | Hewlett, Mrs. (Mary D Kingcome) | female | 55 | 0 | 0 | 248706 | 16 | S | |
17 | 0 | 3 | Rice, Master. Eugene | male | 2 | 4 | 1 | 382652 | 29.12 | Q | |
18 | 1 | 2 | Williams, Mr. Charles Eugene | male | 22 | 0 | 0 | 244373 | 13 | S | |
19 | 0 | 3 | Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele) | female | 31 | 1 | 0 | 345763 | 18 | S | |
20 | 1 | 3 | Masselmani, Mrs. Fatima | female | 64 | 0 | 0 | 2649 | 7.22 | C | |
21 | 0 | 2 | Fynney, Mr. Joseph J | male | 35 | 0 | 0 | 239865 | 26 | S | |
22 | 1 | 2 | Beesley, Mr. Lawrence | male | 34 | 0 | 0 | 248698 | 13 | D56 | S |
23 | 1 | 3 | "McGowan, Miss. Anna ""Annie""" | female | 15 | 0 | 0 | 330923 | 8.02 | Q | |
24 | 1 | 1 | Sloper, Mr. William Thompson | male | 28 | 0 | 0 | 113788 | 35.5 | A6 | S |
25 | 0 | 3 | Palsson, Miss. Torborg Danira | female | 8 | 3 | 1 | 349909 | 21.07 | S | |
26 | 1 | 3 | Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson) | female | 38 | 1 | 5 | 347077 | 31.38 | S | |
27 | 0 | 3 | Emir, Mr. Farred Chehab | male | 21 | 0 | 0 | 2631 | 7.22 | C | |
28 | 0 | 1 | Fortune, Mr. Charles Alexander | male | 19 | 3 | 2 | 19950 | 263 | C23 C25 C27 | S |
29 | 1 | 3 | "O'Dwyer, Miss. Ellen ""Nellie""" | female | 37 | 0 | 0 | 330959 | 7.87 | Q | |
30 | 0 | 3 | Todoroff, Mr. Lalio | male | 38 | 0 | 0 | 349216 | 7.89 | S | |
31 | 0 | 1 | Uruchurtu, Don. Manuel E | male | 40 | 0 | 0 | PC 17601 | 27.72 | C | |
32 | 1 | 1 | Spencer, Mrs. William Augustus (Marie Eugenie) | female | 42 | 1 | 0 | PC 17569 | 146.52 | B78 | C |
33 | 1 | 3 | Glynn, Miss. Mary Agatha | female | 41 | 0 | 0 | 335677 | 7.75 | Q | |
34 | 0 | 2 | Wheadon, Mr. Edward H | male | 66 | 0 | 0 | C.A. 24579 | 10.5 | S | |
35 | 0 | 1 | Meyer, Mr. Edgar Joseph | male | 28 | 1 | 0 | PC 17604 | 82.17 | C | |
36 | 0 | 1 | Holverson, Mr. Alexander Oskar | male | 42 | 1 | 0 | 113789 | 52 | S | |
37 | 1 | 3 | Mamee, Mr. Hanna | male | 27 | 0 | 0 | 2677 | 7.22 | C | |
38 | 0 | 3 | Cann, Mr. Ernest Charles | male | 21 | 0 | 0 | A./5. 2152 | 8.05 | S | |
39 | 0 | 3 | Vander Planke, Miss. Augusta Maria | female | 18 | 2 | 0 | 345764 | 18 | S | |
40 | 1 | 3 | Nicola-Yarred, Miss. Jamila | female | 14 | 1 | 0 | 2651 | 11.24 | C | |
41 | 0 | 3 | Ahlin, Mrs. Johan (Johanna Persdotter Larsson) | female | 40 | 1 | 0 | 7546 | 9.47 | S | |
42 | 0 | 2 | Turpin, Mrs. William John Robert (Dorothy Ann Wonnacott) | female | 27 | 1 | 0 | 11668 | 21 | S | |
43 | 0 | 3 | Kraeff, Mr. Theodor | male | 21 | 0 | 0 | 349253 | 7.89 | C | |
44 | 1 | 2 | Laroche, Miss. Simonne Marie Anne Andree | female | 3 | 1 | 2 | SC/Paris 2123 | 41.57 | C | |
45 | 1 | 3 | Devaney, Miss. Margaret Delia | female | 19 | 0 | 0 | 330958 | 7.87 | Q | |
46 | 0 | 3 | Rogers, Mr. William John | male | 4 | 0 | 0 | S.C./A.4. 23567 | 8.05 | S | |
47 | 0 | 3 | Lennon, Mr. Denis | male | 54 | 1 | 0 | 370371 | 15.5 | Q | |
48 | 1 | 3 | O'Driscoll, Miss. Bridget | female | 32 | 0 | 0 | 14311 | 7.75 | Q | |
49 | 0 | 3 | Samaan, Mr. Youssef | male | 29 | 2 | 0 | 2662 | 21.67 | C | |
50 | 0 | 3 | Arnold-Franchi, Mrs. Josef (Josefine Franchi) | female | 18 | 1 | 0 | 349237 | 17.8 | S | |
51 | 0 | 3 | Panula, Master. Juha Niilo | male | 7 | 4 | 1 | 3101295 | 39.68 | S | |
52 | 0 | 3 | Nosworthy, Mr. Richard Cater | male | 21 | 0 | 0 | A/4. 39886 | 7.8 | S | |
53 | 1 | 1 | Harper, Mrs. Henry Sleeper (Myna Haxtun) | female | 49 | 1 | 0 | PC 17572 | 76.72 | D33 | C |
54 | 1 | 2 | Faunthorpe, Mrs. Lizzie (Elizabeth Anne Wilkinson) | female | 29 | 1 | 0 | 2926 | 26 | S | |
55 | 0 | 1 | Ostby, Mr. Engelhart Cornelius | male | 65 | 0 | 1 | 113509 | 61.97 | B30 | C |
56 | 1 | 1 | Woolner, Mr. Hugh | male | 70 | 0 | 0 | 19947 | 35.5 | C52 | S |
57 | 1 | 2 | Rugg, Miss. Emily | female | 21 | 0 | 0 | C.A. 31026 | 10.5 | S | |
58 | 0 | 3 | Novel, Mr. Mansouer | male | 28 | 0 | 0 | 2697 | 7.22 | C | |
59 | 1 | 2 | West, Miss. Constance Mirium | female | 5 | 1 | 2 | C.A. 34651 | 27.75 | S | |
60 | 0 | 3 | Goodwin, Master. William Frederick | male | 11 | 5 | 2 | CA 2144 | 46.9 | S | |
61 | 0 | 3 | Sirayanian, Mr. Orsen | male | 22 | 0 | 0 | 2669 | 7.22 | C | |
62 | 1 | 1 | Icard, Miss. Amelie | female | 38 | 0 | 0 | 113572 | 80 | B28 | |
63 | 0 | 1 | Harris, Mr. Henry Birkhardt | male | 45 | 1 | 0 | 36973 | 83.47 | C83 | S |
64 | 0 | 3 | Skoog, Master. Harald | male | 4 | 3 | 2 | 347088 | 27.9 | S | |
65 | 0 | 1 | Stewart, Mr. Albert A | male | 55 | 0 | 0 | PC 17605 | 27.72 | C | |
66 | 1 | 3 | Moubarek, Master. Gerios | male | 52 | 1 | 1 | 2661 | 15.24 | C | |
67 | 1 | 2 | Nye, Mrs. (Elizabeth Ramell) | female | 29 | 0 | 0 | C.A. 29395 | 10.5 | F33 | S |
68 | 0 | 3 | Crease, Mr. Ernest James | male | 19 | 0 | 0 | S.P. 3464 | 8.15 | S | |
69 | 1 | 3 | Andersson, Miss. Erna Alexandra | female | 17 | 4 | 2 | 3101281 | 7.925 | S | |
70 | 0 | 3 | Kink, Mr. Vincenz | male | 26 | 2 | 0 | 315151 | 8.66 | S | |
71 | 0 | 2 | Jenkin, Mr. Stephen Curnow | male | 32 | 0 | 0 | C.A. 33111 | 10.5 | S | |
72 | 0 | 3 | Goodwin, Miss. Lillian Amy | female | 16 | 5 | 2 | CA 2144 | 46.9 | S | |
73 | 0 | 2 | Hood, Mr. Ambrose Jr | male | 21 | 0 | 0 | S.O.C. 14879 | 73.5 | S | |
74 | 0 | 3 | Chronopoulos, Mr. Apostolos | male | 26 | 1 | 0 | 2680 | 14.45 | C | |
75 | 1 | 3 | Bing, Mr. Lee | male | 32 | 0 | 0 | 1601 | 56.49 | S | |
76 | 0 | 3 | Moen, Mr. Sigurd Hansen | male | 25 | 0 | 0 | 348123 | 7.65 | F G73 | S |
77 | 0 | 3 | Staneff, Mr. Ivan | male | 87 | 0 | 0 | 349208 | 7.89 | S | |
78 | 0 | 3 | Moutal, Mr. Rahamin Haim | male | 32 | 0 | 0 | 374746 | 8.05 | S | |
79 | 1 | 2 | Caldwell, Master. Alden Gates | male | 12 | 0 | 2 | 248738 | 29 | S | |
80 | 1 | 3 | Dowdell, Miss. Elizabeth | female | 30 | 0 | 0 | 364516 | 12.47 | S | |
81 | 0 | 3 | Waelens, Mr. Achille | male | 22 | 0 | 0 | 345767 | 9 | S | |
82 | 1 | 3 | Sheerlinck, Mr. Jan Baptist | male | 29 | 0 | 0 | 345779 | 9.5 | S | |
83 | 1 | 3 | McDermott, Miss. Brigdet Delia | female | 34 | 0 | 0 | 330932 | 7.78 | Q | |
84 | 0 | 1 | Carrau, Mr. Francisco M | male | 28 | 0 | 0 | 113059 | 47.1 | S | |
85 | 1 | 2 | Ilett, Miss. Bertha | female | 17 | 0 | 0 | SO/C 14885 | 10.5 | S | |
86 | 1 | 3 | Backstrom, Mrs. Karl Alfred (Maria Mathilda Gustafsson) | female | 33 | 3 | 0 | 3101278 | 15.85 | S | |
87 | 0 | 3 | Ford, Mr. William Neal | male | 16 | 1 | 3 | W./C. 6608 | 34.37 | S | |
88 | 0 | 3 | Slocovski, Mr. Selman Francis | male | 23 | 0 | 0 | SOTON/OQ 392086 | 8.05 | S | |
89 | 1 | 1 | Fortune, Miss. Mabel Helen | female | 23 | 3 | 2 | 19950 | 263 | C23 C25 C27 | S |
90 | 0 | 3 | Celotti, Mr. Francesco | male | 24 | 0 | 0 | 343275 | 8.05 | S | |
91 | 0 | 3 | Christmann, Mr. Emil | male | 29 | 0 | 0 | 343276 | 8.05 | S | |
92 | 0 | 3 | Andreasson, Mr. Paul Edvin | male | 20 | 0 | 0 | 347466 | 7.85 | S | |
93 | 0 | 1 | Chaffee, Mr. Herbert Fuller | male | 46 | 1 | 0 | W.E.P. 5734 | 61.1 | E31 | S |
94 | 0 | 3 | Dean, Mr. Bertram Frank | male | 26 | 1 | 2 | C.A. 2315 | 20.5 | S | |
95 | 0 | 3 | Coxon, Mr. Daniel | male | 59 | 0 | 0 | 364500 | 7.25 | S | |
96 | 0 | 3 | Shorney, Mr. Charles Joseph | male | 73 | 0 | 0 | 374910 | 8.05 | S | |
97 | 0 | 1 | Goldschmidt, Mr. George B | male | 71 | 0 | 0 | PC 17754 | 34.6 | A5 | C |
98 | 1 | 1 | Greenfield, Mr. William Bertram | male | 23 | 0 | 1 | PC 17759 | 63.3 | D10 D12 | C |
99 | 1 | 2 | Doling, Mrs. John T (Ada Julia Bone) | female | 34 | 0 | 1 | 231919 | 23 | S | |
100 | 0 | 2 | Kantor, Mr. Sinai | male | 34 | 1 | 0 | 244367 | 26 | S | |
101 | 0 | 3 | Petranec, Miss. Matilda | female | 28 | 0 | 0 | 349245 | 7.8 | S | |
102 | 0 | 3 | "Petroff, Mr. Pastcho (""Pentcho"")" | male | 87 | 0 | 0 | 349215 | 7.8 | S | |
103 | 0 | 1 | White, Mr. Richard Frasar | male | 21 | 0 | 1 | 35281 | 77.2 | D26 | S |
104 | 0 | 3 | Johansson, Mr. Gustaf Joel | male | 33 | 0 | 0 | 7540 | 8.65 | S | |
105 | 0 | 3 | Gustafsson, Mr. Anders Vilhelm | male | 37 | 2 | 0 | 3101276 | 7.92 | S | |
106 | 0 | 3 | Mionoff, Mr. Stoytcho | male | 28 | 0 | 0 | 349207 | 7.89 | S | |
107 | 1 | 3 | Salkjelsvik, Miss. Anna Kristine | female | 21 | 0 | 0 | 343120 | 7.65 | S | |
108 | 1 | 3 | Moss, Mr. Albert Johan | male | 31 | 0 | 0 | 312991 | 7.77 | S | |
109 | 0 | 3 | Rekic, Mr. Tido | male | 38 | 0 | 0 | 349249 | 7.89 | S | |
110 | 1 | 3 | Moran, Miss. Bertha | female | 36 | 1 | 0 | 371110 | 24.15 | Q | |
111 | 0 | 1 | Porter, Mr. Walter Chamberlain | male | 47 | 0 | 0 | 110465 | 52 | C110 | S |
112 | 0 | 3 | Zabour, Miss. Hileni | female | 14 | 1 | 0 | 2665 | 14.45 | C | |
113 | 0 | 3 | Barton, Mr. David John | male | 22 | 0 | 0 | 324669 | 8.05 | S | |
114 | 0 | 3 | Jussila, Miss. Katriina | female | 20 | 1 | 0 | 4136 | 9.82 | S | |
115 | 0 | 3 | Attalah, Miss. Malake | female | 17 | 0 | 0 | 2627 | 14.45 | C | |
116 | 0 | 3 | Pekoniemi, Mr. Edvard | male | 21 | 0 | 0 | STON/O 2. 3101294 | 7.92 | S | |
117 | 0 | 3 | Connors, Mr. Patrick | male | 70 | 0 | 0 | 370369 | 7.75 | Q | |
118 | 0 | 2 | Turpin, Mr. William John Robert | male | 29 | 1 | 0 | 11668 | 21 | S | |
119 | 0 | 1 | Baxter, Mr. Quigg Edmond | male | 24 | 0 | 1 | PC 17558 | 247.52 | B58 B60 | C |
120 | 0 | 3 | Andersson, Miss. Ellis Anna Maria | female | 2 | 4 | 2 | 347082 | 31.27 | S | |
121 | 0 | 2 | Hickman, Mr. Stanley George | male | 21 | 2 | 0 | S.O.C. 14879 | 73.5 | S | |
122 | 0 | 3 | Moore, Mr. Leonard Charles | male | 39 | 0 | 0 | A4. 54510 | 8.05 | S | |
123 | 0 | 2 | Nasser, Mr. Nicholas | male | 32 | 1 | 0 | 237736 | 30.07 | C | |
124 | 1 | 2 | Webber, Miss. Susan | female | 32 | 0 | 0 | 27267 | 13 | E101 | S |
125 | 0 | 1 | White, Mr. Percival Wayland | male | 54 | 0 | 1 | 35281 | 77.28 | D26 | S |
126 | 1 | 3 | Nicola-Yarred, Master. Elias | male | 12 | 1 | 0 | 2651 | 11.24 | C | |
127 | 0 | 3 | McMahon, Mr. Martin | male | 9 | 0 | 0 | 370372 | 7.75 | Q | |
128 | 1 | 3 | Madsen, Mr. Fridtjof Arne | male | 24 | 0 | 0 | C 17369 | 7.14 | S | |
129 | 1 | 3 | Peter, Miss. Anna | female | 45 | 1 | 1 | 2668 | 22.35 | F E69 | C |
130 | 0 | 3 | Ekstrom, Mr. Johan | male | 45 | 0 | 0 | 347061 | 6.97 | S | |
131 | 0 | 3 | Drazenoic, Mr. Jozef | male | 33 | 0 | 0 | 349241 | 7.58 | C | |
132 | 0 | 3 | Coelho, Mr. Domingos Fernandeo | male | 20 | 0 | 0 | SOTON/O.Q. 3101307 | 7.05 | S | |
133 | 0 | 3 | Robins, Mrs. Alexander A (Grace Charity Laury) | female | 47 | 1 | 0 | A/5. 3337 | 14.5 | S | |
134 | 1 | 2 | Weisz, Mrs. Leopold (Mathilde Francoise Pede) | female | 29 | 1 | 0 | 228414 | 26 | S | |
135 | 0 | 2 | Sobey, Mr. Samuel James Hayden | male | 25 | 0 | 0 | C.A. 29178 | 13 | S | |
136 | 0 | 2 | Richard, Mr. Emile | male | 23 | 0 | 0 | SC/PARIS 2133 | 15.04 | C | |
137 | 1 | 1 | Newsom, Miss. Helen Monypeny | female | 19 | 0 | 2 | 11752 | 26.28 | D47 | S |
138 | 0 | 1 | Futrelle, Mr. Jacques Heath | male | 37 | 1 | 0 | 113803 | 53.1 | C123 | S |
139 | 0 | 3 | Osen, Mr. Olaf Elon | male | 16 | 0 | 0 | 7534 | 9.21 | S | |
140 | 0 | 1 | Giglio, Mr. Victor | male | 24 | 0 | 0 | PC 17593 | 79.2 | B86 | C |
141 | 0 | 3 | Boulos, Mrs. Joseph (Sultana) | female | 66 | 0 | 2 | 2678 | 15.24 | C | |
142 | 1 | 3 | Nysten, Miss. Anna Sofia | female | 22 | 0 | 0 | 347081 | 7.75 | S | |
143 | 1 | 3 | Hakkarainen, Mrs. Pekka Pietari (Elin Matilda Dolck) | female | 24 | 1 | 0 | STON/O2. 3101279 | 15.85 | S | |
144 | 0 | 3 | Burke, Mr. Jeremiah | male | 19 | 0 | 0 | 365222 | 6.75 | Q | |
145 | 0 | 2 | Andrew, Mr. Edgardo Samuel | male | 18 | 0 | 0 | 231945 | 11.5 | S | |
146 | 0 | 2 | Nicholls, Mr. Joseph Charles | male | 19 | 1 | 1 | C.A. 33112 | 36.75 | S | |
147 | 1 | 3 | "Andersson, Mr. August Edvard (""Wennerstrom"")" | male | 27 | 0 | 0 | 350043 | 7.79 | S | |
148 | 0 | 3 | "Ford, Miss. Robina Maggie ""Ruby""" | female | 9 | 2 | 2 | W./C. 6608 | 34.37 | S | |
149 | 0 | 2 | "Navratil, Mr. Michel (""Louis M Hoffman"")" | male | 36 | 0 | 2 | 230080 | 26 | F2 | S |
150 | 0 | 2 | Byles, Rev. Thomas Roussel Davids | male | 42 | 0 | 0 | 244310 | 13 | S | |
151 | 0 | 2 | Bateman, Rev. Robert James | male | 51 | 0 | 0 | S.O.P. 1166 | 12.52 | S | |
152 | 1 | 1 | Pears, Mrs. Thomas (Edith Wearne) | female | 22 | 1 | 0 | 113776 | 66.6 | C2 | S |
153 | 0 | 3 | Meo, Mr. Alfonzo | male | 56 | 0 | 0 | A.5. 11206 | 8.05 | S | |
154 | 0 | 3 | van Billiard, Mr. Austin Blyler | male | 41 | 0 | 2 | A/5. 851 | 14.5 | S | |
155 | 0 | 3 | Olsen, Mr. Ole Martin | male | 42 | 0 | 0 | Fa 265302 | 7.31 | S | |
156 | 0 | 1 | Williams, Mr. Charles Duane | male | 51 | 0 | 1 | PC 17597 | 61.37 | C |
ProgC02.81☘
Concevoir un programme permettant d'obtenir la table des identifiants et des noms des femmes de plus de 30 ans ayant survécu.
La table à obtenir
[{'PassengerId': 2, 'Name': 'Cumings, Mrs. John Bradley (Florence Briggs Thayer)'},
{'PassengerId': 4, 'Name': 'Futrelle, Mrs. Jacques Heath (Lily May Peel)'},
{'PassengerId': 12, 'Name': 'Bonnell, Miss. Elizabeth'},
{'PassengerId': 16, 'Name': 'Hewlett, Mrs. (Mary D Kingcome) '},
{'PassengerId': 20, 'Name': 'Masselmani, Mrs. Fatima'},
{'PassengerId': 26, 'Name': 'Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)'},
{'PassengerId': 29, 'Name': 'O\'Dwyer, Miss. Ellen "Nellie"'},
{'PassengerId': 32, 'Name': 'Spencer, Mrs. William Augustus (Marie Eugenie)'},
{'PassengerId': 33, 'Name': 'Glynn, Miss. Mary Agatha'},
{'PassengerId': 48, 'Name': "O'Driscoll, Miss. Bridget"},
{'PassengerId': 53, 'Name': 'Harper, Mrs. Henry Sleeper (Myna Haxtun)'},
{'PassengerId': 62, 'Name': 'Icard, Miss. Amelie'},
{'PassengerId': 83, 'Name': 'McDermott, Miss. Brigdet Delia'},
{'PassengerId': 86, 'Name': 'Backstrom, Mrs. Karl Alfred (Maria Mathilda Gustafsson)'},
{'PassengerId': 99, 'Name': 'Doling, Mrs. John T (Ada Julia Bone)'},
{'PassengerId': 110, 'Name': 'Moran, Miss. Bertha'},
{'PassengerId': 124, 'Name': 'Webber, Miss. Susan'},
{'PassengerId': 129, 'Name': 'Peter, Miss. Anna'}]
Un code à trous
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Une solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
ProgC02.82☘
Complétez la définition de la fonction proportion_survivants()
puis déterminer
la proportion de survivants dans chacune des trois classes du bateau.
3 4 5 6 7 8 |
|
Les proportions à obtenir
La proportion de survivants de la classe 1: 0.4.
La proportion de survivants de la classe 2: 0.5.
La proportion de survivants de la classe 3: 0.3.
Une solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
ProgC02.83☘
Rédigez un programme qui :
- extrait la table des survivants ;
- trie cette table selon l'ordre croissant des numéros de classe ;
- trie ensuite selon l'ordre croissant des âges ;
- construit la table
table_titanic2
constituée uniquement des noms, classes et âges de ces passagers survivants.
La table à obtenir
[{'Pclass': '1', 'Name': 'Newsom, Miss. Helen Monypeny', 'Age': 19},
{'Pclass': '1', 'Name': 'Pears, Mrs. Thomas (Edith Wearne)', 'Age': 22},
{'Pclass': '1', 'Name': 'Fortune, Miss. Mabel Helen', 'Age': 23},
{'Pclass': '1', 'Name': 'Greenfield, Mr. William Bertram', 'Age': 23},
{'Pclass': '1', 'Name': 'Sloper, Mr. William Thompson', 'Age': 28},
{'Pclass': '1', 'Name': 'Futrelle, Mrs. Jacques Heath (Lily May Peel)', 'Age': 35},
{'Pclass': '1', 'Name': 'Cumings, Mrs. John Bradley (Florence Briggs Thayer)', 'Age': 38},
{'Pclass': '1', 'Name': 'Icard, Miss. Amelie', 'Age': 38},
{'Pclass': '1', 'Name': 'Spencer, Mrs. William Augustus (Marie Eugenie)', 'Age': 42},
{'Pclass': '1', 'Name': 'Harper, Mrs. Henry Sleeper (Myna Haxtun)', 'Age': 49},
{'Pclass': '1', 'Name': 'Bonnell, Miss. Elizabeth', 'Age': 58},
{'Pclass': '1', 'Name': 'Woolner, Mr. Hugh', 'Age': 70},
{'Pclass': '2', 'Name': 'Laroche, Miss. Simonne Marie Anne Andree', 'Age': 3},
{'Pclass': '2', 'Name': 'West, Miss. Constance Mirium', 'Age': 5},
{'Pclass': '2', 'Name': 'Caldwell, Master. Alden Gates', 'Age': 12},
{'Pclass': '2', 'Name': 'Nasser, Mrs. Nicholas (Adele Achem)', 'Age': 14},
{'Pclass': '2', 'Name': 'Ilett, Miss. Bertha', 'Age': 17},
{'Pclass': '2', 'Name': 'Rugg, Miss. Emily', 'Age': 21},
{'Pclass': '2', 'Name': 'Williams, Mr. Charles Eugene', 'Age': 22},
{'Pclass': '2', 'Name': 'Faunthorpe, Mrs. Lizzie (Elizabeth Anne Wilkinson)', 'Age': 29},
{'Pclass': '2', 'Name': 'Nye, Mrs. (Elizabeth Ramell)', 'Age': 29},
{'Pclass': '2', 'Name': 'Weisz, Mrs. Leopold (Mathilde Francoise Pede)', 'Age': 29},
{'Pclass': '2', 'Name': 'Webber, Miss. Susan', 'Age': 32},
{'Pclass': '2', 'Name': 'Beesley, Mr. Lawrence', 'Age': 34},
{'Pclass': '2', 'Name': 'Doling, Mrs. John T (Ada Julia Bone)', 'Age': 34},
{'Pclass': '2', 'Name': 'Hewlett, Mrs. (Mary D Kingcome) ', 'Age': 55},
{'Pclass': '3', 'Name': 'Sandstrom, Miss. Marguerite Rut', 'Age': 4},
{'Pclass': '3', 'Name': 'Nicola-Yarred, Master. Elias', 'Age': 12},
{'Pclass': '3', 'Name': 'Nicola-Yarred, Miss. Jamila', 'Age': 14},
{'Pclass': '3', 'Name': 'McGowan, Miss. Anna "Annie"', 'Age': 15},
{'Pclass': '3', 'Name': 'Andersson, Miss. Erna Alexandra', 'Age': 17},
{'Pclass': '3', 'Name': 'Devaney, Miss. Margaret Delia', 'Age': 19},
{'Pclass': '3', 'Name': 'Salkjelsvik, Miss. Anna Kristine', 'Age': 21},
{'Pclass': '3', 'Name': 'Nysten, Miss. Anna Sofia', 'Age': 22},
{'Pclass': '3', 'Name': 'Madsen, Mr. Fridtjof Arne', 'Age': 24},
{'Pclass': '3', 'Name': 'Hakkarainen, Mrs. Pekka Pietari (Elin Matilda Dolck)', 'Age': 24},
{'Pclass': '3', 'Name': 'Heikkinen, Miss. Laina', 'Age': 26},
{'Pclass': '3', 'Name': 'Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)', 'Age': 27},
{'Pclass': '3', 'Name': 'Mamee, Mr. Hanna', 'Age': 27},
{'Pclass': '3', 'Name': 'Andersson, Mr. August Edvard ("Wennerstrom")', 'Age': 27},
{'Pclass': '3', 'Name': 'Sheerlinck, Mr. Jan Baptist', 'Age': 29},
{'Pclass': '3', 'Name': 'Dowdell, Miss. Elizabeth', 'Age': 30},
{'Pclass': '3', 'Name': 'Moss, Mr. Albert Johan', 'Age': 31},
{'Pclass': '3', 'Name': "O'Driscoll, Miss. Bridget", 'Age': 32},
{'Pclass': '3', 'Name': 'Bing, Mr. Lee', 'Age': 32},
{'Pclass': '3', 'Name': 'Backstrom, Mrs. Karl Alfred (Maria Mathilda Gustafsson)', 'Age': 33},
{'Pclass': '3', 'Name': 'McDermott, Miss. Brigdet Delia', 'Age': 34},
{'Pclass': '3', 'Name': 'Moran, Miss. Bertha', 'Age': 36},
{'Pclass': '3', 'Name': 'O\'Dwyer, Miss. Ellen "Nellie"', 'Age': 37},
{'Pclass': '3', 'Name': 'Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)', 'Age': 38},
{'Pclass': '3', 'Name': 'Glynn, Miss. Mary Agatha', 'Age': 41},
{'Pclass': '3', 'Name': 'Peter, Miss. Anna', 'Age': 45},
{'Pclass': '3', 'Name': 'Moubarek, Master. Gerios', 'Age': 52},
{'Pclass': '3', 'Name': 'Masselmani, Mrs. Fatima', 'Age': 64}]
Une solution
Attention, il faut penser à transformer les âges en entier sinon la chaîne
de caractères '5'
est triée après la chaîne de caractères '34'
par
exemple...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
ProgC02.84☘
Rédigez un programme qui :
- extrait la liste des hommes survivants ;
- trie cette liste selon l'ordre croissant des numéros de classe ;
- trie ensuite selon l'ordre décroissant des âges ;
- construit la table
table_titanic3
constituée uniquement des noms, classes et âges de ces passagers survivants.
La table à obtenir
[{'Pclass': '1', 'Name': 'Woolner, Mr. Hugh', 'Age': 70},
{'Pclass': '1', 'Name': 'Sloper, Mr. William Thompson', 'Age': 28},
{'Pclass': '1', 'Name': 'Greenfield, Mr. William Bertram', 'Age': 23},
{'Pclass': '2', 'Name': 'Beesley, Mr. Lawrence', 'Age': 34},
{'Pclass': '2', 'Name': 'Williams, Mr. Charles Eugene', 'Age': 22},
{'Pclass': '2', 'Name': 'Caldwell, Master. Alden Gates', 'Age': 12},
{'Pclass': '3', 'Name': 'Moubarek, Master. Gerios', 'Age': 52},
{'Pclass': '3', 'Name': 'Bing, Mr. Lee', 'Age': 32},
{'Pclass': '3', 'Name': 'Moss, Mr. Albert Johan', 'Age': 31},
{'Pclass': '3', 'Name': 'Sheerlinck, Mr. Jan Baptist', 'Age': 29},
{'Pclass': '3', 'Name': 'Mamee, Mr. Hanna', 'Age': 27},
{'Pclass': '3', 'Name': 'Andersson, Mr. August Edvard ("Wennerstrom")', 'Age': 27},
{'Pclass': '3', 'Name': 'Madsen, Mr. Fridtjof Arne', 'Age': 24},
{'Pclass': '3', 'Name': 'Nicola-Yarred, Master. Elias', 'Age': 12}]
Une solution
Attention, il faut penser à transformer les âges en entier sinon la chaîne
de caractères '5'
est triée après la chaîne de caractères '34'
par exemple...
from fonctions_csv import *
def Age(dico):
return dico["Age"]
def Classe(dico):
return dico["Pclass"]
##----- Programme principal -----##
table_titanic = importe_csv('titanic.csv')
hommes_survivants = [dico for dico in table_titanic if dico['Survived'] == '1' and dico['Sex'] == 'male']
attributs_entiers(hommes_survivants, 'Age')
table_titanic3 = projection(hommes_survivants, ['Name', 'Pclass', 'Age'])
table_titanic3.sort(key=Age, reverse=True)
table_titanic3.sort(key=Classe)
for dico in table_titanic3:
print(dico)