import json
import os
def afficher_taches(taches):
"""Affiche toutes les tâches."""
if not taches:
print("📭 Aucune tâche pour le moment.")
else:
print("\n📋 Liste des tâches :")
for i, tache in enumerate(taches, 1):
statut = "✅" if tache['terminee'] else "❌"
print(f"{i}. {tache['titre']} [{statut}]")
def ajouter_tache(taches):
"""Ajoute une nouvelle tâche."""
titre = input("🆕 Entrez le titre de la nouvelle tâche : ")
if titre.strip() == "":
print("⛔ Le titre ne peut pas être vide.")
return
taches.append({"titre": titre, "terminee": False})
print("✅ Tâche ajoutée avec succès.")
def marquer_terminee(taches):
"""Marque une tâche comme terminée."""
afficher_taches(taches)
try:
indice = int(input("✔️ Numéro de la tâche à marquer comme terminée : ")) -
1
if 0 <= indice < len(taches):
taches[indice]['terminee'] = True
print("👍 Tâche marquée comme terminée.")
else:
print("❌ Numéro invalide.")
except ValueError:
print("⚠️ Veuillez entrer un nombre valide.")
def supprimer_tache(taches):
"""Supprime une tâche."""
afficher_taches(taches)
try:
indice = int(input(" Numéro de la tâche à supprimer : ")) - 1
if 0 <= indice < len(taches):
taches.pop(indice)
print("🧹 Tâche supprimée.")
else:
print("❌ Numéro invalide.")
except ValueError:
print("⚠️ Veuillez entrer un nombre valide.")
def menu():
"""Affiche le menu et gère les choix."""
taches = charger_taches()
while True:
print("\n=== MENU ===")
print("1. Afficher les tâches")
print("2. Ajouter une tâche")
print("3. Marquer une tâche comme terminée")
print("4. Supprimer une tâche")
print("5. Quitter")
choix = input("Votre choix : ")
if choix == '1':
afficher_taches(taches)
elif choix == '2':
ajouter_tache(taches)
elif choix == '3':
marquer_terminee(taches)
elif choix == '4':
supprimer_tache(taches)
elif choix == '5':
sauvegarder_taches(taches)
print("👋 À bientôt !")
break
else:
print("❌ Choix invalide. Réessayez.")
if __name__ == "__main__":
menu()