*حل مشروع المكتبة *

هذا حلي لمشروع المكتبة لقد انهيته الان كان سهل جداً لم اكن اتوقع انه بهذه السهولة:

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")
إعجابَين (2)

حلك يمشي الحال لكن رح تنصدم من حل المستر هههههههه, عمل دالة لكل وظيفة من الاربعة او الثلاث والله نسيت, وايضا في هذا المشروع تعلمت نقطة True & False فالـ if الشرطية او غيرها

إعجابَين (2)

اعلم هذا لكن لم يختلف كثيرا ساقوم بوضع كل شرط في دالة

3 إعجابات

لا تنسى تشارك الكود بعد الانتهاء

3 إعجابات

كيف الحال بالنسبة اليك هل هو صعب سهل طويل ؟

إعجاب واحد (1)

الحل كان سهل جداً لم اكون اتوقع انه بهذه السهولة انهيته في اربع ساعات من التفكير و الكتابة

إعجابَين (2)