هذا حلي لمشروع المكتبة لقد انهيته الان كان سهل جداً لم اكن اتوقع انه بهذه السهولة:
def clear ():
import os
os.system ("cls" if os.name == "nt" else "clear")
library = {}
while True:
print ("""
Menu:
1. Add Book
2. Check out Book
3. Check in Book
4. List Book
5. Exit
""")
choice = input ("Enter your choice (1-5): ")
# اضافة كتاب إلى مخزن الكتب
if choice == "1":
while True:
clear ()
while True:
isbn = input ("Enter ISBN: ")
if isbn.isdigit ():
break
title = input ("Enter title: ")
author = input ("Enter author: ")
library [isbn] = {"title":title,"author":author,"available":True}
print (f"Book '{title}' by {author} added to the catalog with ISBN {isbn}.")
another_book =input ("Do you want to add another book?(y/n): ")
if another_book != "y":
break
# استعارة كتاب من المخزن
elif choice == "2":
while True:
clear ()
while True:
isbn = input ("Enter ISBN to check out: ")
if isbn in library:
break
if library [isbn]["available"]==True:
print ("Book ",{library [isbn] ["title"]}, " checked out successfully. ")
library [isbn]["available"] = False
else:
print ("sorry, the book is currently checked out.")
another_book = input ("Do you want to check out another book?(y/n): ")
if another_book != "y":
break
# ارجاع كتاب للمخزن
elif choice == "3":
while True:
clear ()
isbn = input ("Enter ISBN to check in: ")
if isbn in library:
library [isbn]["available"]=True
print ("Book ",library[isbn]["title"]," checked in successfully ")
else:
print ("Book not found in the catalog. ")
another_book = input ("Do you want to check in another book?(y/n): ")
if another_book != "y":
break
# عرض كل الكتب في المخزن
elif choice == "4":
while True:
clear ()
for isbn in library:
print ("ISBN: ",isbn, ", Title: ",library[isbn]["title"], ", Author: ",library[isbn]["author"], ", Available: ",library[isbn]["available"])
go_back = input ("Do you want to go back the main menu? (y/n): ")
if go_back == "y":
break
# الخروج من البرنامج
elif choice == "5":
clear ()
print ("exiting the program... ")
break
# اختيار مختلف
else:
clear ()
print ("Please choose from 1,2,3,4,5")