مشروع راىع و القواميس فعلا مفيدة جدا في تخزين البيانات بطريقة جد منظمة…
الحمد لله استطعت حل التحدي قبل مشاهدة الحل في التطبيق…فخور جدا اني وصلت لهذا المستوى…
طبعا الحل هو بطريقتي الخاصة…فعلا تبدو معقدة مقارنة بطريقة الأستاذ…لكن لا بأس أنا أتطور باستمرار…
سأشارك معكم الكود…جربته مرارا وهو يعمل جيدا…
طبعا موقع ريبليت الآن لا يسمح لي بتطوير المزيد…اظنه يتحول الى النسخة المدفوعة…
قد تحدث أخطاء غير متوقعة بسبب النسخ واللصق…المهم أني وصلت
الفلو شارت يومين وانا اخطط له…
import os
def clear_screen():
os.system ("cls" if os.name=="nt" else "clear")
my_books = {}
while True:
clear_screen()
print ("""Welcom to [Noor Library]\n
1- Add a book.
2- Check out a book.
3- Check in a book.
4- View books.
5- Exit.""")
choose = input ("Please choose from 1-5: ")
# add books
if choose == "1":
while True:
clear_screen()
isbn = input ("\nEnter ISBN: ")
# must be integer
if isbn.isdigit():
title = input ("Enter the title: ")
author = input ("Enter the author: ")
my_books [int (isbn)] = {'title':title, 'author':author, 'available':True}
print (f"\nThe book ({title}) by ({author}) "
f"with ISBN {isbn} was added successfully.")
add_another = input ("\nDo you want to add another book 'y/n': ")
if add_another=='y':
continue
elif add_another=='n':
break
else:
input ("Invalid choice! Please try again...")
continue
# ISBN isn't a number!
else:
input ("Invalid ISBN ! Please try again...")
# check out
elif choose == "2":
while True:
clear_screen()
out_isbn = input ("Enter ISBN: ")
# must be integer
if out_isbn.isdigit():
out_isbn = int (out_isbn)
# is exist / is available
if out_isbn in my_books:
if my_books[out_isbn]['available']:
my_books[out_isbn]['available'] = False
print (f"\nThe book ({my_books[out_isbn]['title']}) "
f"by ({my_books[out_isbn]['author']}) "
f"with ISBN: {out_isbn}, was checked out successfully.")
# not available for check out
else:
print ("Sorry this book is currently checked out.")
# not exist
else:
print ("Sorry this book isn't exist in our library.")
out_another = input ("\nDo you want to check out another book 'y/n': ")
if out_another == "y":
continue
elif out_another == "n":
break
else:
input ("Invalide choice! Please try again...")
continue
# ISBN not a number!
else:
input ("Invalide ISBN ! Please try again... ")
continue
# check in
elif choose == "3":
while True:
clear_screen()
in_isbn = input ("Enter ISBN: ")
# must be integer
if in_isbn.isdigit():
in_isbn = int (in_isbn)
# is exist / available for check in
if in_isbn in my_books:
if my_books[in_isbn] ['available'] is False:
my_books[in_isbn]['available'] = True
print (f"\nThe book ({my_books[in_isbn]['title']}) "
f"by ({my_books[in_isbn]['author']}) "
f"with ISBN: {in_isbn}, was checked in successfully.")
# already checked in !
else:
print ("This book is already checked in.")
# not exist
else:
print ("Sorry this book isn't exist in our library.")
in_another = input ("\nDo you want to check in another book 'y/n': ")
if in_another == 'y':
continue
elif in_another == 'n':
break
else:
input ("Invalide choice! Please try again...")
continue
# ISBN not a number!
else:
input ("Invalide ISBN ! Please try again... ")
continue
# view
elif choose == "4":
clear_screen()
for key in my_books:
print (f"ISBN: {key}, "
f"Title: {my_books[key]['title']}, "
f"Author: {my_books[key]['author']}, "
f"Available: {my_books[key]['available']}")
input ("\nPress enter to return..")
continue
# exit
elif choose == "5":
print("Exit...")
break
# invalid
else:
input ("Invalid choice! Press enter to restart... ")
continue