posts.py

Created by alban-scientifique

Created on November 07, 2023

1.74 KB


import kandinsky as kd

# Définition d'une liste pour stocker les tâches
taches = []

# Fonction pour ajouter une tâche à la liste
def ajouter_tache(tache):
    taches.append(tache)

# Fonction pour afficher la liste des tâches
def afficher_taches():
    kd.clear()
    kd.draw_string(10, 10, "Liste des tâches:", (0, 0, 0))
    y = 30
    for i, tache in enumerate(taches, start=1):
        kd.draw_string(10, y, "{}. {}".format(i, tache), (0, 0, 0))
        y += 20
    kd.display()

# Fonction pour supprimer une tâche de la liste
def supprimer_tache(choix):
    if 1 <= choix <= len(taches):
        tache_supprimee = taches.pop(choix - 1)
        return "Tâche '{}' supprimée avec succès.".format(tache_supprimee)
    else:
        return "Numéro de tâche invalide."

# Boucle principale
while True:
    kd.fill_rect(0, 0, 320, 240, (255, 255, 255))
    kd.draw_string(10, 10, "Gestionnaire de tâches", (0, 0, 0))
    kd.draw_string(10, 30, "1. Ajouter une tâche", (0, 0, 0))
    kd.draw_string(10, 50, "2. Afficher les tâches", (0, 0, 0))
    kd.draw_string(10, 70, "3. Supprimer une tâche", (0, 0, 0)
    kd.draw_string(10, 90, "4. Quitter", (0, 0, 0))
    kd.display()

    choix = int(input())

    if choix == 1:
        tache = input("Entrez la tâche à ajouter : ")
        ajouter_tache(tache)
    elif choix == 2:
        afficher_taches()
    elif choix == 3:
        num_tache = int(input("Entrez le numéro de la tâche à supprimer : "))
        message = supprimer_tache(num_tache)
        kd.draw_string(10, 200, message, (0, 0, 0))
        kd.display()
        kd.wait(1000)
    elif choix == 4:
        break
    else:
        kd.draw_string(10, 200, "Opération non valide.", (0, 0, 0))
        kd.display()
        kd.wait(1000)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.