# Projet 03 — Le Podium # Algorithme : Tri par sélection athletes = [ {"nom": "Marcus", "pays": "JAM", "temps": 9.97}, {"nom": "Alice", "pays": "FRA", "temps": 9.85}, {"nom": "Yusuf", "pays": "TUR", "temps": 10.03}, {"nom": "Carla", "pays": "BRA", "temps": 9.97}, {"nom": "Bob", "pays": "USA", "temps": 9.91}, {"nom": "Lena", "pays": "GER", "temps": 10.11}, {"nom": "Kwame", "pays": "GHA", "temps": 9.99}, {"nom": "Sofia", "pays": "ITA", "temps": 10.07}, ] def tri_selection_athletes(athletes): """ Trie la liste d'athlètes par temps croissant (tri par sélection). Le meilleur (temps le plus bas) sera en premier. """ n = len(athletes) for i in range(n): mini = i for j in range(i + 1, n): # TODO : comparer les temps pour trouver le minimum if ...: mini = j athletes[i], athletes[mini] = athletes[mini], athletes[i] return athletes def afficher_podium(athletes): """Affiche un podium ASCII avec les 3 premiers athlètes.""" if len(athletes) < 3: print("Pas assez d'athlètes pour un podium !") return or_ = athletes[0] ar_ = athletes[1] br_ = athletes[2] print() print(" 🥇") print(" ┌───┐ 🥈 🥉") print(" │ │ ┌───┐ ┌───┐") print(" │ 1 │ │ 2 │ │ 3 │") print(" │ │ │ │ │ │") print(" └───┘ └───┘ └───┘") print(f" {or_['nom']:^10} ({or_['pays']}) {ar_['nom']:^10} ({ar_['pays']}) {br_['nom']:^10} ({br_['pays']})") print(f" {or_['temps']} s {ar_['temps']} s {br_['temps']} s") print() def temps_atteint(temps_liste, t): """ Recherche dichotomique : retourne True si le temps t a été réalisé par un athlète, False sinon. La liste temps_liste doit être triée. """ a = 0 b = len(temps_liste) - 1 while a <= b: m = (a + b) // 2 if temps_liste[m] == t: return True elif temps_liste[m] < t: # TODO pass else: # TODO pass return False # --- Programme principal --- print("=== Compétition de Sprint ===") print() print("Résultats bruts :") for a in athletes: print(f" {a['nom']} ({a['pays']}) : {a['temps']} s") tri_selection_athletes(athletes) afficher_podium(athletes) # Classement complet print("Classement final :") for i, a in enumerate(athletes, 1): print(f" {i}. {a['nom']} ({a['pays']}) — {a['temps']} s") # Recherche dichotomique temps_liste = [a["temps"] for a in athletes] print() for t in [9.85, 10.00, 9.97]: trouve = temps_atteint(temps_liste, t) print(f"Temps {t}s réalisé ? {'Oui' if trouve else 'Non'}")