# 1️ Liste de livres, chaque livre est un dictionnaire
bibliotheque = [
    {"titre": "Le Petit Prince", "auteur": "Antoine de Saint-Exupéry", "disponible": True},
    {"titre": "Harry Potter", "auteur": "J.K. Rowling", "disponible": True},
    {"titre": "1984", "auteur": "George Orwell", "disponible": True}
]

# 2️ Fonction pour afficher les livres
def afficher_livres(liste_livres):
    for livre in liste_livres:
        status = "Disponible" if livre["disponible"] else "Emprunté"
        print(f"{livre['titre']} par {livre['auteur']} - {status}")

# 3️ Fonction pour ajouter un livre
def ajouter_livre(titre, auteur):
    bibliotheque.append({"titre": titre, "auteur": auteur, "disponible": True})
    print(f"{titre} ajouté à la bibliothèque.")

# 4️ Fonction pour emprunter un livre
def emprunter_livre(titre):
    for livre in bibliotheque:
        if livre["titre"].lower() == titre.lower():
            if livre["disponible"]:
                livre["disponible"] = False
                print(f"Vous avez emprunté {titre}.")
                return
            else:
                print(f"{titre} est déjà emprunté.")
                return
    print(f"{titre} n'est pas dans la bibliothèque.")

# 5️ Exemple d'utilisation
print(" Bibliothèque actuelle :")
afficher_livres(bibliotheque)

ajouter_livre("Le Seigneur des Anneaux", "J.R.R. Tolkien")
emprunter_livre("1984")

print("\n Bibliothèque mise à jour :")
afficher_livres(bibliotheque)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: