# Initialisation de la bibliothèque
bibliotheque = {}
def ajouter_livre(bibliotheque, identifiant, titre, auteur, annee, copies):
bibliotheque[identifiant] = {
'titre': titre,
'auteur': auteur,
'annee': annee,
'copies_disponibles': copies
}
def emprunter_livre(bibliotheque, identifiant):
if identifiant in bibliotheque and bibliotheque[identifiant]['copies_disponibles'] > 0:
bibliotheque[identifiant]['copies_disponibles'] -= 1
print(f"Livre emprunté: {bibliotheque[identifiant]['titre']}")
else:
print("Livre non disponible pour l'emprunt.")
def rendre_livre(bibliotheque, identifiant):
if identifiant in bibliotheque:
bibliotheque[identifiant]['copies_disponibles'] += 1
print(f"Livre rendu: {bibliotheque[identifiant]['titre']}")
else:
print("Identifiant de livre invalide.")
def verifier_disponibilite(bibliotheque, identifiant):
if identifiant in bibliotheque:
print(f"Copies disponibles pour '{bibliotheque[identifiant]['titre']}': {bibliotheque[identifiant]['copies_disponibles']}")
else:
print("Identifiant de livre invalide.")
# Exemple d'utilisation
ajouter_livre(bibliotheque, "1", "1984", "George Orwell", 1949, 3)
ajouter_livre(bibliotheque, "2", "Le Petit Prince", "Antoine de Saint-Exupéry", 1943, 2)
emprunter_livre(bibliotheque, "1")
verifier_disponibilite(bibliotheque, "1")
rendre_livre(bibliotheque, "1")
verifier_disponibilite(bibliotheque, "1")