ajout exercices, corrections diverses, glossaire
- Ajout des 10 TPs d'évaluation (sans PDF) - Création GLOSSAIRE.md et AMELIORATIONS.md - Corrections f-strings, eval(), sommaires Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
264
representation_construits/evaluation/TP07_Manga_aide.md
Normal file
264
representation_construits/evaluation/TP07_Manga_aide.md
Normal file
@@ -0,0 +1,264 @@
|
||||
# Aide - TP07 Manga
|
||||
|
||||
## Rappels utiles
|
||||
|
||||
### Structure des mangas (dictionnaires)
|
||||
```python
|
||||
# Chaque manga est un dictionnaire
|
||||
manga = mangas[0]
|
||||
print(manga["titre"]) # "One Piece"
|
||||
print(manga["auteur"]) # "Eiichiro Oda"
|
||||
print(manga["genres"]) # ["Aventure", "Action"]
|
||||
print(manga["tomes"]) # 107
|
||||
print(manga["termine"]) # False
|
||||
print(manga["note"]) # 9.2
|
||||
```
|
||||
|
||||
### Collection personnelle (dictionnaire)
|
||||
```python
|
||||
# ma_collection = {titre: [liste des tomes possedes]}
|
||||
ma_collection = {
|
||||
"Death Note": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||
"One Piece": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
}
|
||||
|
||||
# Acceder aux tomes d'un manga
|
||||
tomes_possedes = ma_collection["Death Note"]
|
||||
print(len(tomes_possedes)) # 12
|
||||
```
|
||||
|
||||
### Parcourir la collection
|
||||
```python
|
||||
for titre, tomes_possedes in ma_collection.items():
|
||||
print(titre, ":", len(tomes_possedes), "tomes")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Exercice 1
|
||||
|
||||
### 1.1 - Affichage d'un manga
|
||||
```python
|
||||
def afficher_manga(manga):
|
||||
titre = manga["titre"]
|
||||
auteur = manga["auteur"]
|
||||
genres = manga["genres"]
|
||||
tomes = manga["tomes"]
|
||||
termine = manga["termine"]
|
||||
note = manga["note"]
|
||||
|
||||
print(titre, "-", auteur)
|
||||
|
||||
# Afficher les genres
|
||||
genres_str = ", ".join(genres)
|
||||
print("Genres:", genres_str)
|
||||
|
||||
# Afficher le statut
|
||||
if termine:
|
||||
statut = "Termine"
|
||||
else:
|
||||
statut = "En cours"
|
||||
|
||||
print(tomes, "tomes (", statut, ") | Note:", note)
|
||||
```
|
||||
|
||||
### 1.2 - Recherche par genre
|
||||
```python
|
||||
def rechercher_par_genre(mangas, genre):
|
||||
resultats = []
|
||||
for manga in mangas:
|
||||
if genre in manga["genres"]:
|
||||
resultats.append(manga)
|
||||
return resultats
|
||||
```
|
||||
|
||||
### 1.3 - Mangas termines
|
||||
```python
|
||||
def mangas_termines(mangas):
|
||||
termines = []
|
||||
for manga in mangas:
|
||||
if manga["termine"] == True:
|
||||
termines.append(manga)
|
||||
|
||||
# Trier par note decroissante
|
||||
termines = sorted(termines, key=lambda m: m["note"], reverse=True)
|
||||
return termines
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Exercice 2
|
||||
|
||||
### 2.1 - Avancement de lecture
|
||||
```python
|
||||
def avancement_collection(ma_coll, mangas):
|
||||
avancement = []
|
||||
|
||||
for titre, tomes_possedes in ma_coll.items():
|
||||
# Trouver le manga dans le catalogue
|
||||
total_tomes = 0
|
||||
for manga in mangas:
|
||||
if manga["titre"] == titre:
|
||||
total_tomes = manga["tomes"]
|
||||
break
|
||||
|
||||
nb_possedes = len(tomes_possedes)
|
||||
|
||||
if total_tomes > 0:
|
||||
pourcentage = round(nb_possedes / total_tomes * 100)
|
||||
else:
|
||||
pourcentage = 0
|
||||
|
||||
complet = (nb_possedes == total_tomes)
|
||||
|
||||
avancement.append({
|
||||
"titre": titre,
|
||||
"possede": nb_possedes,
|
||||
"total": total_tomes,
|
||||
"pourcentage": pourcentage,
|
||||
"complet": complet
|
||||
})
|
||||
|
||||
return avancement
|
||||
```
|
||||
|
||||
### 2.2 - Tomes manquants
|
||||
```python
|
||||
def tomes_manquants(titre, ma_coll, mangas):
|
||||
# Trouver le nombre total de tomes
|
||||
total_tomes = 0
|
||||
for manga in mangas:
|
||||
if manga["titre"] == titre:
|
||||
total_tomes = manga["tomes"]
|
||||
break
|
||||
|
||||
# Recuperer les tomes possedes
|
||||
if titre in ma_coll:
|
||||
possedes = ma_coll[titre]
|
||||
else:
|
||||
possedes = []
|
||||
|
||||
# Trouver les manquants
|
||||
manquants = []
|
||||
for i in range(1, total_tomes + 1):
|
||||
if i not in possedes:
|
||||
manquants.append(i)
|
||||
|
||||
return manquants
|
||||
```
|
||||
|
||||
### 2.3 - Valeur de la collection
|
||||
```python
|
||||
def valeur_collection(ma_coll, prix_par_tome):
|
||||
nb_tomes = 0
|
||||
|
||||
for titre, tomes in ma_coll.items():
|
||||
nb_tomes = nb_tomes + len(tomes)
|
||||
|
||||
valeur = nb_tomes * prix_par_tome
|
||||
|
||||
return {
|
||||
"nb_tomes": nb_tomes,
|
||||
"valeur_totale": valeur
|
||||
}
|
||||
```
|
||||
|
||||
### 2.4 - Note moyenne des mangas possedes
|
||||
```python
|
||||
def note_moyenne_collection(ma_coll, mangas):
|
||||
total_notes = 0
|
||||
nb_mangas = 0
|
||||
|
||||
for titre in ma_coll.keys():
|
||||
# Trouver le manga dans le catalogue
|
||||
for manga in mangas:
|
||||
if manga["titre"] == titre:
|
||||
total_notes = total_notes + manga["note"]
|
||||
nb_mangas = nb_mangas + 1
|
||||
break
|
||||
|
||||
if nb_mangas == 0:
|
||||
return 0
|
||||
|
||||
return round(total_notes / nb_mangas, 2)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Exercice 3 (Bonus)
|
||||
|
||||
### 3.1 - Recommandation
|
||||
```python
|
||||
def recommander(ma_coll, mangas):
|
||||
# Collecter les genres de ma collection
|
||||
mes_genres = []
|
||||
for titre in ma_coll.keys():
|
||||
for manga in mangas:
|
||||
if manga["titre"] == titre:
|
||||
for g in manga["genres"]:
|
||||
if g not in mes_genres:
|
||||
mes_genres.append(g)
|
||||
|
||||
# Chercher le meilleur manga non possede
|
||||
meilleur = None
|
||||
meilleur_score = 0
|
||||
|
||||
for manga in mangas:
|
||||
if manga["titre"] not in ma_coll:
|
||||
# Compter les genres en commun
|
||||
genres_communs = 0
|
||||
for g in manga["genres"]:
|
||||
if g in mes_genres:
|
||||
genres_communs = genres_communs + 1
|
||||
|
||||
score = genres_communs + manga["note"]
|
||||
|
||||
if score > meilleur_score:
|
||||
meilleur = manga
|
||||
meilleur_score = score
|
||||
|
||||
return meilleur
|
||||
```
|
||||
|
||||
### 3.2 - Auteurs uniques
|
||||
```python
|
||||
def auteurs_uniques(mangas):
|
||||
auteurs = []
|
||||
for manga in mangas:
|
||||
auteur = manga["auteur"]
|
||||
if auteur not in auteurs:
|
||||
auteurs.append(auteur)
|
||||
auteurs.sort()
|
||||
return auteurs
|
||||
```
|
||||
|
||||
### 3.3 - Statistiques par genre
|
||||
```python
|
||||
def stats_par_genre(mangas):
|
||||
# Collecter les donnees par genre
|
||||
donnees = {}
|
||||
|
||||
for manga in mangas:
|
||||
for genre in manga["genres"]:
|
||||
if genre not in donnees:
|
||||
donnees[genre] = {"nb": 0, "total_notes": 0}
|
||||
donnees[genre]["nb"] = donnees[genre]["nb"] + 1
|
||||
donnees[genre]["total_notes"] = donnees[genre]["total_notes"] + manga["note"]
|
||||
|
||||
# Calculer les moyennes
|
||||
stats = {}
|
||||
for genre, data in donnees.items():
|
||||
moyenne = round(data["total_notes"] / data["nb"], 2)
|
||||
stats[genre] = {"nombre": data["nb"], "note_moyenne": moyenne}
|
||||
|
||||
return stats
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Pieges a eviter
|
||||
|
||||
1. **Genres en liste** : les genres sont une liste `["Action", "Aventure"]`, utilisez `in` pour verifier
|
||||
2. **Collection vs catalogue** : `ma_collection` contient les titres possedes, `mangas` contient les infos completes
|
||||
3. **Division par zero** : verifiez que le diviseur est > 0 avant de calculer une moyenne
|
||||
4. **Tomes manquants** : n'oubliez pas que les tomes sont numerotes de 1 a total_tomes
|
||||
Reference in New Issue
Block a user